我看到人们使用数组中的参数,像这样正确的使用方法DI在angularJS
myAngularApp.controller("nameOfController", ["$firstDependency", "$secondDependency", function ($firstDependency, $secondDependency) {
// code here
}]);
另一方面手我看到下面的代码也无一不是工作
myAngularApp.controller("nameOfController", function ($firstDependency, $secondDependency) {
// code here
});
在角度文档中,我看到了数组的使用。为什么角度允许后一种方法?哪一个是绝对推荐?事实上,在角度文档样本中,指令不使用数组。
指定的数组仅用于最小化您的代码。这通常是您可以采取的最佳方法 – scniro