2016-12-15 3 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

지시어와 컨트롤러를 분리 된 두 개의 파일로 분리 해보십시오. 그런 다음 평소처럼 컨트롤러에서 주입을 할 수 있습니다. – 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 is undefined' –

관련 문제