Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何以以下方式在指令控制器中注入依赖项?_Angularjs_Dependency Injection_Angular Directive - Fatal编程技术网

Angularjs 如何以以下方式在指令控制器中注入依赖项?

Angularjs 如何以以下方式在指令控制器中注入依赖项?,angularjs,dependency-injection,angular-directive,Angularjs,Dependency Injection,Angular Directive,我在angular应用程序中使用的是ng strict di模式。它抛出了一个错误 throbberController未使用显式注释,无法在严格模式下调用 我的代码是: app.directive('throbberDirective', [ '_$ajax', function(_$ajax){ return { restrict: "EA", templateUrl: "common/utils/thr

我在angular应用程序中使用的是
ng strict di
模式。它抛出了一个错误

throbberController未使用显式注释,无法在严格模式下调用

我的代码是:

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.$inject=['$scope']throbberController未定义
正常。谢谢
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;

}