我看到人們使用數組中的參數,像這樣正確的使用方法DI在angularJS
myAngularApp.controller("nameOfController", ["$firstDependency", "$secondDependency", function ($firstDependency, $secondDependency) {
// code here
}]);
另一方面手我看到下面的代碼也無一不是工作
myAngularApp.controller("nameOfController", function ($firstDependency, $secondDependency) {
// code here
});
在角度文檔中,我看到了數組的使用。爲什麼角度允許後一種方法?哪一個是絕對推薦?事實上,在角度文檔樣本中,指令不使用數組。
指定的數組僅用於最小化您的代碼。這通常是您可以採取的最佳方法 – scniro