【发布时间】:2014-06-01 13:39:18
【问题描述】:
好吧,在解决了这个臭名昭著的问题之后,我现在正式秃顶了:缩小的 AngularJS 应用程序无法正常工作,解决了这个错误:
错误:[$injector:unpr] 未知提供者:aProvider http://errors.angularjs.org/1.2.6/$injector/unpr?p0=aProvider%20%3C-%20a 在http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:11492 在http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26946 在 Object.c [as get] (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26250) 在http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:27041 在 c (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26250) 在 Object.d [作为调用] (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26496) 在http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:9:910 在 Object.f [as forEach] (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:11927) 在http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:9:856 在 j (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:5:27235)
很多其他人也有这个问题,但看起来可以通过将依赖项声明为数组而不是裸函数参数来解决,如下所示:
angular.module('my-app').controller('LoginCtrl', [ '$scope', 'HttpService', function($scope, HttpService) { ... }]);
而不是这个:
angular.module('my-app').controller('LoginCtrl', function($scope, HttpService) { ... });
但在我的情况下它不起作用。我检查了我所有的脚本(咖啡和生成的 javascript),它们都使用正确的数组样式声明。
问题显然不是来自额外的包。我尝试将所有额外的包引用移出 <!-- bower:js --> 块(这样它们就不会被 grunt 缩小),但问题仍然存在。这意味着,这是我的代码的错……但话又说回来,我尝试了(似乎是)唯一可用的修复程序,但无济于事。
任何提示,即使是关于如何正确调试它?
提前致谢!
【问题讨论】:
-
您能否禁用缩小并查看哪个提供商抛出此错误。
-
好吧,如果我禁用缩小并只使用
grunt serve,则不会引发错误 - 应用程序运行良好。 -
一一禁用您的模块,以检测代码中存在错误的部分。你在某处有一个 DI 错误。
-
问题是,如果我禁用一个模块,整个应用程序将拒绝启动,从而无法调试。
-
检查这个项目:github.com/btford/ngmin。 NgMin 应该有助于缩小你的 Angular 应用程序。
标签: javascript angularjs coffeescript gruntjs