Javascript 缩小的AngularJS给了我无法读取的错误
这是我使用angular.js时的堆栈跟踪:Javascript 缩小的AngularJS给了我无法读取的错误,javascript,angularjs,Javascript,Angularjs,这是我使用angular.js时的堆栈跟踪: [$injector:unpr] Unknown provider: editorPopupManagerProvider <- editorPopupManager <- libStateManager <- libInjectionManager http://errors.angularjs.org/1.2.2/$injector/unpr?p0=editorPopupManagerProvider%20%3C-%20edit
[$injector:unpr] Unknown provider: editorPopupManagerProvider <- editorPopupManager <- libStateManager <- libInjectionManager
http://errors.angularjs.org/1.2.2/$injector/unpr?p0=editorPopupManagerProvider%20%3C-%20editorPopupManager%20%3C-%20libStateManager%20%3C-%20libInjectionManager
这只是一个简单的例子,但有时缩小的错误甚至一点帮助都没有
在这两种情况下,我都希望出现第一个堆栈跟踪:当我使用angular.js和angular.min.js时。
导致此异常的代码中没有问题。我特意制作它,是为了演示angular.min.js缩小堆栈跟踪并使其难以理解的问题。如果这样做的原因是为了避免最终用户看到堆栈跟踪,我理解。但是我需要正常的可读堆栈跟踪,以便将其发送到日志服务器。您未知的提供程序名称可能正被minifier操纵/损坏,因此您需要使用以下语法进行更正:
myApp.controller('MyCtrl' ['$scope', function ($scope) {
// do stuff with '$scope'
}]);
请注意函数是如何包装在数组中的,这将保留依赖项的命名约定,以便在字符串未损坏时可以安全地重新映射它们:
myApp.controller('MyCtrl' ['$scope', function (a) {
// do stuff with 'a'
}]);
然后可以添加其他依赖项(它们需要按照指定的顺序显示):
如果您确实为控制器使用了数组声明,那么这很可能是一些指令声明。通常我们会这样做:
.controller('MyGreatCtrl',
[ '$scope','$stateParams', // even minified version does is correctly injected
function($scope , $stateParams ,) {
...
即使缩小了,上述代码也能正常工作
但是,我们应该以同样的方式做的是指令
声明。我们可以这样做(错误,缩小时出现问题):
虽然这是正确的方法:
.directive('myGreatDirective',
[function () {
var directive =
{
restrict: 'E',
...
// the Array declaration also here
controller: ['$scope','$element','$attrs',
function ($scope , $element , $attrs) {
...
};
}],
};
return directive;
以及更多细节的链接
老实说,这是我的问题…你的问题是什么?你期待什么?在开发中使用未统一的版本使调试更容易。即使我面临这个问题,也可以使用这种依赖项注释样式
someModule.factory('greeter',['$window',function(重命名为$window){…}])代码>在整个应用程序中。问题在于您在哪里定义了editorPopupManagerProvider
。另外,您能否发布editorPopupManagerProvider
code?谢谢。我解决了从大口中取出丑陋的管道的问题。:)你真厉害。它解决了我的错误:[$injector:unpr]未知提供程序:eProvider
.controller('MyGreatCtrl',
[ '$scope','$stateParams', // even minified version does is correctly injected
function($scope , $stateParams ,) {
...
.directive('myGreatDirective',
[function () {
var directive =
{
restrict: 'E',
...
controller: function ($scope , $element , $attrs) {
...
};
}],
};
return directive;
.directive('myGreatDirective',
[function () {
var directive =
{
restrict: 'E',
...
// the Array declaration also here
controller: ['$scope','$element','$attrs',
function ($scope , $element , $attrs) {
...
};
}],
};
return directive;