AngularJS错误:未知提供者:aProvider < - a

An *_*han 16 javascript coffeescript angularjs gruntjs

好吧,我已经正式秃顶了,因为我已经用这个臭名昭着的问题拉了我的头发:minfied AngularJS应用程序只是不起作用,这个错误被抛出:

错误:[$ injector:unpr]未知提供者:aProvider < - 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),网址为:http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:27041 at 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 at 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 at j(http:// localhost/my -app/dist/scripts/1bde0e2e.vendor.js:5:27235)

很多其他人也有这个问题,但看起来它可以通过将依赖关系声明为数组而不是裸函数参数来修复,如下所示:

angular.module('my-app').controller('LoginCtrl', [ '$scope', 'HttpService', function($scope, HttpService) { ... }]);
Run Code Online (Sandbox Code Playgroud)

而不是这个:

angular.module('my-app').controller('LoginCtrl', function($scope, HttpService) { ... });
Run Code Online (Sandbox Code Playgroud)

但它在我的情况下不起作用.我检查了所有脚本(咖啡和生成的javascripts),它们都使用正确的数组样式声明.

这个问题显然不是来自额外的包装.我尝试将所有额外的包引用移出<!-- bower:js -->块(这样它们不会被grunt缩小),但问题仍然存在.这意味着,这是我的代码责备...但是再次,我已经尝试了(似乎是)唯一可用的修复,但无济于事.

任何提示,即使是如何正确调试这个?

提前致谢!

An *_*han 27

最后我发现了问题.是的,这是我错过的DI错误.

所有谁可以从相同的头痛痛苦:阵列格式的声明必须做在$routeProviderresolve选项,以及.在我的情况下(提前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()
        ]
    # ...
])
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!