我遇到了那个烦人的 Angular 缩小问题(我真的希望这个问题在 Angular 2 中不存在)
我已经注释掉了我所有的应用程序模块注入,并逐个列出了问题所在,我认为我将其范围缩小到了我的searchPopoverDirectives:
你能看出我做错了什么吗?
原始代码,产生此错误 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;
}
}
})
})();
然后我尝试了[]
语法以尝试修复缩小问题并遇到此错误 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));
})
}
}
})