2016-12-15 7 views
2

角度アプリでng-strict-diモードを使用しています。ディレクティブコントローラに依存関係を挿入するにはどうすればいいですか?

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']; 
    } 
]); 

どのように明示的に注入する:それは

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

私のコードは、エラーがスローされますか?私は間違って何かしていますか?私はこれを解決するのに役立ちます。

+0

ディレクティブとそのコントローラーを2つの別々のファイルに分けてください。それからあなたはコントローラの中で通常どおりに注射をすることができます。 – 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は定義されていません。 ' –

関連する問題