1

I am using ng-strict-di mode in my angular app. It throws an error

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

my code is:

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

How to inject explicitly? Am I doing anything wrong? Help me solve this.

2
  • Try separating the directive and it's controller into two separate files. Then you can do injection like you normally would, in the controller. Commented Dec 15, 2016 at 13:05
  • Why it is not happening here? Commented Dec 15, 2016 at 13:10

1 Answer 1

1
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;

}
Sign up to request clarification or add additional context in comments.

2 Comments

Why the previous process of mine has failed?
throbberController.$inject = ['$scope']; in this line throbberController is undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.