AngularJS定义angular.module()多次 [英] AngularJS defining angular.module() multiple times
问题描述
什么是叫 angular.module('Mymodule中')
多次的行为?
例如,我想定义在单独的.js文件我的路线和我的指令。
这安全吗?
例如:
// routes.js
angular.module('应用',['$带'])
的.config(函数($ routeProvider,$ locationProvider){
...
});//directives.js
angular.module(应用)
.directive('的formInput',函数(){
...
此外,什么是定义依赖多次的影响?这是添加剂,或后进赢了?
例如:
angular.module(名称[,要求],configFn);
结果......结果
要求(可选) - {阵列=} - 如果指定然后正在创建新的模块。如果未指定则模块检索进行进一步的配置。
- angular.module文档
块引用>我会间preT是如下:你只能定义依赖一次 - 第一次调用angular.module特定模块。您可以拨打angular.module()多次之后,但
要求
选项不得指定。What is the behaviour of calling
angular.module('myModule')
multiple times?For example, I wish to define my routes and my directives in separate .js files.
Is this safe?
eg:
//routes.js angular.module('app',['$strap']) .config(function($routeProvider, $locationProvider) { ... }); //directives.js angular.module('app') .directive('formInput', function() { ...
Also, what is the impact of defining the dependencies multiple times? Is this additive, or last-in-wins?
eg:
解决方案angular.module(name[, requires], configFn);
...
requires(optional) – {Array.=} – If specified then new module is being created. If unspecified then the the module is being retrieved for further configuration. -- angular.module docsI would interpret that as follows: you can only define the dependencies once -- the first time you call angular.module for a particular module. You can call angular.module() multiple times after that, but the
requires
option must not be specified.这篇关于AngularJS定义angular.module()多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!