2016-12-15 56 views
2

我在我的角度應用程序中使用ng-strict-di模式。它拋出一個錯誤如何通過以下方式在指令控制器中注入依賴項?

throbberController is not using explicit annotation and cannot be invoked in strict mode

我的代碼是:

app.directive('throbberDirective', 
[ 
    '_$ajax', 
    function(_$ajax){ 
     return { 
      restrict: "EA", 
      templateUrl: "common/utils/throbbers/throbber.html", 
      controller: throbberController 
     } 
     function throbberController($scope){ 
      $scope.throbber = _$ajax.getThrobberConfigs(); 
      $scope.throbber.templateName = $scope.throbber.templateName; 

     } 
     throbberController.$inject = ['$scope']; 
    } 
]); 

如何明確地注入?我做錯了什麼?幫我解決這個問題。

+0

嘗試將指令和它的控制器分隔成兩個單獨的文件。然後你可以在控制器中像通常那樣進行注射。 – rrd

+0

爲什麼它不在這裏發生? – SaiUnique

回答

2
app.directive('throbberDirective', 
[ 
    function(){ 
     return { 
      restrict: "EA", 
      templateUrl: "common/utils/throbbers/throbber.html", 
      controller: throbberController 
     } 
    } 
]); 
app.controller('throbberController', throbberController); 
throbberController.$inject = ['$scope', '_$ajax']; 
function throbberController($scope){ 
    $scope.throbber = _$ajax.getThrobberConfigs(); 
    $scope.throbber.templateName = $scope.throbber.templateName; 

} 
+1

這工作正常。謝謝。 – SaiUnique

+0

爲什麼我以前的過程失敗了? – SaiUnique

+1

'throbberController。$ inject = ['$ scope'];'在此行中'throbberController未定義' –