2016-01-21 56 views
-1

我試圖找到發現它,但沒有一個答案...... 在下面的簡單代碼:什麼是angular.js中的「[]」符號?

var app = angular.module('myApp', []); 

使用「[]」的牌子我從來沒有見過一個例子。它是爲了什麼?

+0

當不需要依賴關係時,只需一個空數組。 – geckob

+2

我想你應該先看看JavaScript是什麼! – azerafati

回答

2

這就是你想要這個模塊所依賴的dependencies數組。

所以如果你需要一個路由系統,你會說,像這樣的東西:

angular.module("app.module", ["ui.router"]); 

這是說app.moduleui.router其路由取決於

你上面的例子僅僅是聲明一個angular module沒有依賴並將其分配給變量app

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**.