• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

缩小的 AngularJS 把了我不可读的错误

用户头像
it1352
帮助1

问题说明

这是我使用 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.

正确答案

#1

您的未知提供程序名称可能正在被 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
系列文章
更多 icon
同类精品
更多 icon
继续加载