简体   繁体   English

如何调试angular [$ injector:modulerr]错误

[英]How to debug angular [$injector:modulerr] errors

I have a growing angular application. 我的角度应用越来越多。 From time to time, I mess things up and get an error of the type: 我不时搞砸了,并得到了类型的错误:

[$injector:modulerr] Failed to instantiate module App due to:

It is often very difficult to find the error based on the error message, especially if there are many files with various controllers etc. 通常很难根据错误消息找到错误,特别是如果有许多文件有各种控制器等。

Is there a way to debug these errors in either Chrome or Firefox ? 有没有办法在Chrome或Firefox中调试这些错误?

Just to illustrate. 只是为了说明。

This is what you get when you load minified version of Angular ( angular.min.js ): 这是你加载Angular( angular.min.js )的缩小版本时得到的:

Error: $injector:modulerr
Module Error
Failed to instantiate module eduApp due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.7/$injector/modulerr?p0=e...)
    at Error (native)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:6:416
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:38:184
    at m (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:7:322)
    at h (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:37:275)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:37:444
    at m (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:7:322)
    at h (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:37:275)
    at fb (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:41:35)
    at d (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:19:463

And this is what you get when you use unminified version ( angular.js ): 这是你使用未经编译的版本( angular.js )时得到的:

Error: $injector:nomod
Module Unavailable
Module 'ui.bootstrap' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

The first error is really painful to solve. 第一个错误真的很难解决。 The second one is much more easier. 第二个更容易。

Happy coding! 快乐的编码!

Minified AngularJS gives me unreadable errors 缩小的AngularJS给了我不可读的错误

... Use the unminified version in development to make it easier to debug. ...在开发中使用未经过说明的版本,以便于调试。

I found the following approach to be somewhat helpful. 我发现以下方法有点帮助。 Use local angular.js file so you can modify it: 使用本地angular.js文件,以便您可以修改它:

  1. Open your angular.js file 打开angular.js文件
  2. Go to lines with the following code: 使用以下代码转到行:
    \nmessage = message + '\\nhttp://errors.angularjs.org/1.3.5/' + message = message +'\\ nhttp://errors.angularjs.org/1.3.5/'+\n  (module ? module + '/' : '') + code; (模块?模块+'/':'')+代码; 
  3. After these two lines add: 在这两行之后添加:
    \nconsole.log(message); 的console.log(消息);\n

Taken from here: http://www.chrisgmyr.com/2014/08/debugging-uncaught-error-injectormodulerr-in-angularjs/ 取自这里: http//www.chrisgmyr.com/2014/08/debugging-uncaught-error-injectormodulerr-in-angularjs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM