缩小的 AngularJS 给了我不可读的错误 [英] Minified AngularJS gives me unreadable errors

查看:24
本文介绍了缩小的 AngularJS 给了我不可读的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我使用 angular.js 时的堆栈跟踪:

This is the stack trace when I use angular.js:

[$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.min.js 时的堆栈跟踪:

And this is the stack trace when I use angular.min.js:

[$injector:unpr] http://errors.angularjs.org/1.2.2/$injector/unpr?p0=editorPopupManagerProvider%20%3C-%20editorPopupManager%20%3C-%20libStateManager%20%3C-%20libInjectionManager

这只是一个简单的例子,但有时缩小的错误甚至无济于事.

This is just a simple example but sometimes the minified error doesn't help even a bit.

我希望在这两种情况下都有第一个堆栈跟踪:当我使用 angular.js 和 angular.min.js 时.我在导致此异常的代码中没有问题.我故意这样做是为了演示我在 angular.min.js 中遇到的问题,即缩小堆栈跟踪并使其很难理解.如果这样做的原因是为了避免最终用户看到堆栈跟踪,我理解.但我需要正常可读的堆栈跟踪才能将其发送到日志服务器.

I expect the first stack trace in both cases: When I use angular.js and angular.min.js. I don't have a problem in the code that led to this exception. I made it on purpose to demonstrate the problem I have with angular.min.js minifying the stack trace and making it really hard to understand. If the reason it does that is to avoid end users to see the stack trace, I understand. But I need the normal-readable stack trace in order to send it to a logging server.

推荐答案

您的未知提供程序名称可能正在被 minifier 操作/修改,因此您需要使用以下语法来纠正它:

Your unknown provider name is probably being manipulated/mangled by the minifier, thus you need to use the following syntax to correct it:

myApp.controller('MyCtrl' ['$scope', function ($scope) {
    // do stuff with '$scope'
}]);

注意函数是如何包装在数组中的,这会保留依赖项的命名约定,因此它们可以安全地重新映射,因为字符串不会被破坏:

Note how the function is wrapped in an Array, this keeps the naming conventions of your dependencies so they can safely be remapped as Strings are not mangled:

myApp.controller('MyCtrl' ['$scope', function (a) {
    // do stuff with 'a'
}]);

然后您可以添加其他依赖项(它们需要按照指定的顺序出现):

Which you can then add your other dependencies (they need to appear in the order as they're specified):

myApp.controller('MyCtrl' ['$scope', 'MyService', function ($scope, MyService) {
    // do stuff...
}]);

这篇关于缩小的 AngularJS 给了我不可读的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆