【发布时间】:2016-11-10 15:01:02
【问题描述】:
我在 Visual Studio 中使用了一个压缩插件,除了这一段 AngularJS 代码外,它大部分都可以工作
这是未缩小的代码:
var svgBuildInterface = angular.module("svgBuildInterface", []);
svgBuildInterface.directive('ngRightClick', function ($parse) {
return function (scope, element, attrs) {
var fn = $parse(attrs.ngRightClick);
element.bind('contextmenu', function (event) {
scope.$apply(function () {
event.preventDefault();
fn(scope, { $event: event });
});
});
};
});
这是失败的漂亮打印的缩小代码:
svgBuildInterface = angular.module("svgBuildInterface", []);
svgBuildInterface.directive("ngRightClick", function(n) {
return function(t, i, r) {
var u = n(r.ngRightClick);
i.bind("contextmenu", function(n) {
t.$apply(function() {
n.preventDefault();
u(t, {
$event: n
})
})
})
}
});
我无法在缩小后的代码中设置断点来找出发生了什么,但是 angularJS 会抛出异常:
Error: [$injector:unpr] http://errors.angularjs.org/1.5.7/
$injector/unpr?p0=nProvider%20%3C-%20n%20%3C-%20ngRightClickDirective
【问题讨论】:
-
你的指令不是缩小安全的:docs.angularjs.org/guide/di#implicit-annotation
标签: angularjs bundling-and-minification