缩小的 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 <- editorPopupManager <- libStateManager <- libInjectionManager
这是我使用 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 <- editorPopupManager <- libStateManager <- libInjectionManager
这只是一个简单的例子,但有时缩小的错误甚至无济于事.
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...
}]);
这篇好文章是转载于:编程之路
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 编程之路
- 本文地址: /reply/detail/tanhcgkhag
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20