![](/img/trans.png)
[英]AngularJS: Argument 'Controller as short' is not a function, got undefined
[英]Varying types in the second argument for controller function in AngularJS?
我對Angular還是很陌生,在查看示例時,我發現有時controller
函數的locals
參數有時只是一個函數,而其他時候則是數組。
angular.module('contentful').controller(
'FormWidgetsController',
['$scope', "$injector", function($scope, $injector){ ... }]);
與
myModule.controller("GroupController", function GroupController($scope){
...
});
這些只是我在一個示例中找到的示例。 查看AngularJS文檔 ,它只是說它們是Controller的本地注入,沒有太多上下文。 谷歌搜索不會產生任何對像我這樣的人有意義的東西。
誰能解釋兩者的區別以及每種實現的作用?
不同之處在於您最小化角度應用程序
angular.module('contentful').controller(
'FormWidgetsController',
['$scope', "$injector", function($scope, $injector){ ... }]);
會變成
angular.module('contentful').controller(
'FormWidgetsController',
['$scope', "$injector", function(a, b){ ... }]);
在這種情況下,如果您不使用數組來探索依賴項,Angular仍會知道您需要什么依賴項以及以什么順序注入它們
myModule.controller("GroupController", function GroupController($scope){
...
});
以及何時會縮小
myModule.controller("GroupController", function GroupController(a){
...
});
現在角度不現在是什么,它會給你錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.