Angularjs 中的多模块 [英] Multiple Module in Angularjs

查看:29
本文介绍了Angularjs 中的多模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Angular 脚本中创建多个模块?我浏览了文档并了解到它是某种主要的方法概念.

Is it possible to create multiple module in an Angular Script? I went through the documentation and learned that it is some kind of main method concept.

我需要一些例子来证明这一点.

I need examples to demonstrate this.

推荐答案

是的,你可以在 angularJS 中定义多个模块,如下所示.

Yes, you can define multiple modules in angularJS as given below.

var myApp = angular.module('myApp', [])
var myApp2 = angular.module('myApp2', [])

但是,不要忘记在每个模块声明期间定义依赖项,如下所示.让我们假设 myApp2 依赖于 myApp.因此,声明将类似于,

However, don't forget to define the dependency during each module declarations as below. Let's assume myApp2 dependent on myApp. Hence, the declaration would be something similar to,

var myApp = angular.module('myApp', [])
var myApp2 = angular.module('myApp2', ['myApp'])

AngularJS 中的模块化帮助我们保持代码清晰易懂,因为我们可以组合多个模块来生成应用程序.但是,我们需要记住的是,我们应该根据组件的功能而不是组件的类型对组件进行模块化.

The modularization in AngularJS helps us to keep the code clarity and easy to understand, as we can combine multiple modules to generate the application. However, we need to keep in mind that, we should modularize the components based on their functionality not by their types.

这篇关于Angularjs 中的多模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆