在Angularjs多模块 [英] Multiple Module in Angularjs

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

问题描述

是否有可能在一个角脚本来创建多个模块?我通过角文档去了,得知这是某种形式的主要方法的概念。

Is it possible to create multiple module in an angular Script?? I went through the angular 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模块化帮助我们保持code清晰,容易理解,因为我们可以将多个模块生成应用程序。然而,我们需要记住的是,我们应该根据其类型各自的功能不是模块化的组件。

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天全站免登陆