如何调试Angular的错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module zvApp due to:
Error: [$injector:unpr] Unknown provider: e
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=e
at http://app.dev/build/js/vendor-53eec796.js:3:19384
有一些提供者未知,但是哪个?我找不到一个简单的方法来调试这个。都试过了…
最有可能的问题是缺乏显式依赖注释(除非ng-annotate与最小化一起使用),在构造函数上使用数组语法 (.service('myService', ['$http', function($http){...
)或 $inject
静态属性 (MyService.$inject=['$q']
)。在游戏后期或精简代码中很难找到它。所以一般的做法是使用 ng-strict-di
与ng-app
指令,而你的开发或运行应用程序与非简化的代码,它会抛出更多的信息错误在你缺乏显式依赖注释的地方。
: -
如果使用ng-app
,则
<html ng-app="myApp" ng-strict-di>
如果是手动引导,则指定为选项。
angular.bootstrap(document, ['myApp'], {
strictDi: true
});
通过打开strict-di
, angular注入器将在实例化之前专门检查显式注释,缺乏显式注释会导致应用程序出错,这通常有助于防止这些问题或在游戏早期发现它们。一般来说,打开strict-di
选项是有帮助的(不需要在生产环境中删除它),在捕获缺乏依赖注入几乎每个定义,包括run, config甚至resolve函数(用于路由器,模态等)。