Angularjs 如何以以下方式在指令控制器中注入依赖项?
我在angular应用程序中使用的是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
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;
}