我遇到了那个恼人的 Angular 缩小问题(我真的希望这个问题在 Angular 2 中不存在)
我已经注释掉了我所有的应用程序模块注入(inject),并逐一查看列表以找出问题所在,我想我将其缩小到我的searchPopoverDirectives:
你能看出我做错了什么吗?
原始代码,生成 this error Unknown provider: eProvider <- e
:
(function() { "use strict";
var app = angular.module('searchPopoverDirectives', [])
.directive('searchPopover', function() {
return {
templateUrl : "popovers/searchPopover/searchPopover.html",
restrict : "E",
scope : false,
controller : function($scope) {
// Init SearchPopover scope:
// -------------------------
var vs = $scope;
vs.searchPopoverDisplay = false;
}
}
})
})();
然后我尝试了 []
语法试图修复缩小问题并遇到 this error Unknown provider: $scopeProvider <- $scope <- searchPopoverDirective
:
(function() { "use strict";
var app = angular.module('searchPopoverDirectives', [])
.directive('searchPopover', ['$scope', function($scope) {
return {
templateUrl : "popovers/searchPopover/searchPopover.html",
restrict : "E",
scope : false,
controller : function($scope) {
// Init SearchPopover scope:
// -------------------------
var vs = $scope;
vs.searchPopoverDisplay = false;
}
}
}])
})();
更新: 还发现这个人导致了问题:
.directive('focusMe', function($timeout, $parse) {
return {
link: function(scope, element, attrs) {
var model = $parse(attrs.focusMe);
scope.$watch(model, function(value) {
if (value === true) {
$timeout(function() {
element[0].focus();
});
}
});
element.bind('blur', function() {
scope.$apply(model.assign(scope, false));
})
}
}
})
最佳答案
当你缩小代码时,它会缩小所有代码,所以你的
controller : function($scope) {
被缩小成类似
的样子controller : function(e) {
所以,就用
controller : ["$scope", function($scope) { ... }]
关于javascript - 我的 Angularjs 缩小错误在哪里?错误$注入(inject)器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127409/