Angular JS-如何提及模块依赖?

时间:2016-05-23 15:22:54

标签: javascript angularjs dependencies

我刚刚开始学习Angular JS Framework,我得到了非常奇怪的疑问:)

例如命名模块后 - moduleNamemoduleName取决于 - anotherModule

然后,你写道:

   var myCoolApp = angular.module('moduleName', ['anotherModule']);

但如果anotherModule取决于anotherAwesomeModule,我应该写一下:

   var myCoolApp = angular.module('moduleName', ['anotherModule', 'anotherAwesomeModule'])

还是会照顾好自己?我想知道..

1 个答案:

答案 0 :(得分:1)

angular.module('anotherModule', ['anotherAwesomeModule']);
angular.module('moduleName', ['anotherModule']);

会奏效。

这是一件好事

angular.module('anotherModule', ['anotherAwesomeModule']);
angular.module('moduleName', ['anotherModule', 'anotherAwesomeModule']);

如果moduleName本身取决于anotherAwesomeModule。即使anotherModule停止依赖它,代码仍然按预期工作。