【发布时间】:2015-05-08 15:23:39
【问题描述】:
我遇到了恼人的 Angular 缩小问题(我真的希望这个问题在 Angular 2 中不存在)
我已经注释掉了我所有的应用程序模块注入,并逐个列出了问题所在,我认为我将其范围缩小到了我的 searchPopoverDirectives:
你能看出我做错了什么吗?
原始代码,产生this errorUnknown 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));
})
}
}
})
【问题讨论】:
-
你在错误的地方尝试了 [] 语法 :-) 将它从指令(你不依赖的地方)移动到控制器函数
-
on update:在这里你的指令解决方案应该可以工作:-)
-
我在缩小之前使用 ng-annotate (github.com/olov/ng-annotate)。它会自动执行此操作。
标签: javascript angularjs minify angularjs-injector