AngularJS 多次定义 angular.module() [英] AngularJS defining angular.module() multiple times
问题描述
多次调用 angular.module('myModule')
的行为是什么?
What is the behaviour of calling angular.module('myModule')
multiple times?
例如,我希望在单独的 .js 文件中定义我的路由和指令.
For example, I wish to define my routes and my directives in separate .js files.
这样安全吗?
例如:
//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?
例如:
推荐答案
angular.module(name[, requires], configFn);
...
requires(optional) – {Array.=} – 如果指定,则正在创建新模块.如果未指定,则正在检索模块以进行进一步配置.-- angular.module 文档
我会这样解释:您只能定义一次依赖项——第一次为特定模块调用 angular.module 时.之后您可以多次调用 angular.module(),但不得指定 requires
选项.
I 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屋!