Injecting services into AngularJS directive controller directly

后端 未结 2 1527
傲寒
傲寒 2021-02-19 07:44

I understand how Angular dependency injection works with directives but wanted clarification on something. I have a dummy test directive as follows:

app.directiv         


        
2条回答
  •  孤街浪徒
    2021-02-19 08:20

    You can do this also. Much better way by splitting directive and its controller in a single file. Or you can write in separate files. But, better understand

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

提交回复
热议问题