我试图找到答案,但没有找到...... 在下面的简单代码中:
var app = angular.module('myApp', [] );
我从未见过使用“[]”符号的示例。它的用途是什么?
答案 0 :(得分:2)
这是您希望此模块依赖的dependencies
数组。
因此,如果你需要一个路由系统,你可以这样说:
angular.module("app.module", ["ui.router"]);
这表示app.module
依赖 ui.router
进行路由。
上面的示例只是声明angular module
无依赖,并将其分配给变量app
。
答案 1 :(得分:1)
示例: -
var navigation = angular.module('navigation',[]); // a sample module in angular.
//now creating a module called myapp. I can use navigation module in myapp as below
var myApp = angular.module('myapp',**['navigation']**); // here myApp module uses navigation module.
如果myapp不需要依赖,请使用如下的空数组。
var myApp = angular.module('myapp',**[ ]**);// pass emty array when **no dependency**.