好吧,我现在正式秃头了,因为这个臭名昭著的问题把我的头发弄得乱七八糟:缩小后的 AngularJS 应用程序无法正常工作,并排除了这个错误:
Error: [$injector:unpr] Unknown provider: aProvider <- a http://errors.angularjs.org/1.2.6/$injector/unpr?p0=aProvider%20%3C-%20a at http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:11492 at http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26946 at Object.c [as get] (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26250) at http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:27041 at c (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26250) at Object.d [as invoke] (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26496) at http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:9:910 at Object.f [as forEach] (http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:11927) at http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:9:856 at 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 -->
block (这样它们就不会被咕噜声缩小),但问题仍然存在。这意味着,这应该归咎于我的代码……但话又说回来,我已经尝试了(似乎)唯一可用的修复程序,但无济于事。
任何提示,甚至关于如何正确调试它?
提前致谢!
最佳答案
终于找到问题所在了。是的,这是我错过的 DI 错误。
对于所有可能遭受同样头痛的人:数组格式声明也必须在 $routeProvider
的 resolve
选项中完成。就我而言(前面的 CoffeeScript):
app.config (['$routeProvider', ($routeProvider) ->
$routeProvider
.when '/',
templateUrl: 'views/main.html'
controller: 'MainCtrl'
resolve:
groups: ['GroupService', (GroupService) -> # I MISSED THIS
return GroupService.getAll()
]
entries: ['EntryService', (EntryService) -> # AND THIS
return EntryService.getAll()
]
# ...
])
希望这对您有所帮助!
关于javascript - AngularJS 错误 : Unknown provider: aProvider <- a,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23130500/