AngularJS调试技术

时间:2014-06-20 10:49:48

标签: angularjs javascript-debugger

故事:

我解决了关于在Google上搜索angularjs的问题,我找到了解决方案 问题是从特定版本的angularjs开始的,当角度团队从库的核心移除了一个模块,现在你必须明确指出你是否使用它。
我所说的模块是“ngRoute”

之前:

<script src="angular.js"></script>
...
var myApp = angular.module('myApp', ['someOtherModule']);

<script src="angular.js"></script>
<script src="angular-route.js"></script>
...
var myApp = angular.module('myApp', ['ngRoute', 'someOtherModule']);
...

这是解决方案 (错误仅包括模块未加载)

我的问题是:

  1. 我如何调试angularjs(用于教学目的)来理解 那个模块没有加载?
  2. 我需要调试什么工具? (如果我 需要它)
  3. 下面的问题导致的消息错误(什么 它对我有用吗?什么是“关键”指示找到 问题?)
  4. 调试此特定问题的任何建议? 是否存在“堆栈跟踪”以跟踪angularjs在内部执行的操作 一步一步?
  5. 错误消息:

    Eccezione non gestita alla riga 3845, colonna 9 in http://localhost:12153/Scripts/angular.js
    
    0x800a139e - Errore di run-time di JavaScript: [$injector:modulerr] Failed to instantiate module TodoApp due to:
    
    Error: [$injector:modulerr] Failed to instantiate module ngRoute due to:
    
    Error: [$injector:nomod] Module 'ngRoute' 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.
    
    http://errors.angularjs.org/1.2.18/$injector/nomod?p0=ngRoute
    
       at Anonymous function (http://localhost:12153/Scripts/angular.js:1643:11)
    
       at ensure (http://localhost:12153/Scripts/angular.js:1567:5)
    
       at module (http://localhost:12153/Scripts/angular.js:1641:7)
    
       at Anonymous function (http://localhost:12153/Scripts/angular.js:3817:11)
    
       at forEach (http://localhost:12153/Scripts/angular.js:320:7)
    
       at loadModules (http://localhost:12153/Scripts/angular.js:3811:5)
    
       at Anonymous function (http://localhost:12153/Scripts/angular.js:3818:11)
    
       at forEach (http://localhost:12153/Scripts/angular.js:320:7)
    
       at loadModules (http://localhost:12153/Scripts/angular.js:3811:5)
    
       at createInjector (http://localhost:12153/Scripts/angular.js:3751:3)
    
    http://errors.angularjs.org/1.2.18/$injector/modulerr?p0=ngRoute&p1=Error%3A%20%5B%24injector%3Anomod%5D%20Module%20'ngRoute'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.18%2F%24injector%2Fnomod%3Fp0%3DngRoute%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1643%3A11)%0A%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1567%3A5)%0A%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1641%3A7)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3817%3A11)%0A%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A320%3A7)%0A%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3811%3A5)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3818%3A11)%0A%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A320%3A7)%0A%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3811%3A5)%0A%20%20%20at%20createInjector%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3751%3A3)
    
       at Anonymous function (http://localhost:12153/Scripts/angular.js:3845:9)
    
       at forEach (http://localhost:12153/Scripts/angular.js:320:7)
    
       at loadModules (http://localhost:12153/Scripts/angular.js:3811:5)
    
       at Anonymous function (http://localhost:12153/Scripts/angular.js:3818:11)
    
       at forEach (http://localhost:12153/Scripts/angular.js:320:7)
    
       at loadModules (http://localhost:12153/Scripts/angular.js:3811:5)
    
       at createInjector (http://localhost:12153/Scripts/angular.js:3751:3)
    
       at doBootstrap (http://localhost:12153/Scripts/angular.js:1410:5)
    
       at bootstrap (http://localhost:12153/Scripts/angular.js:1425:5)
    
       at angularInit (http://localhost:12153/Scripts/angular.js:1338:5)
    
    http://errors.angularjs.org/1.2.18/$injector/modulerr?p0=TodoApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20Failed%20to%20instantiate%20module%20ngRoute%20due%20to%3A%0AError%3A%20%5B%24injector%3Anomod%5D%20Module%20'ngRoute'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.18%2F%24injector%2Fnomod%3Fp0%3DngRoute%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1643%3A11)%0A%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1567%3A5)%0A%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1641%3A7)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3817%3A11)%0A%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A320%3A7)%0A%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3811%3A5)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3818%3A11)%0A%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A320%3A7)%0A%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3811%3A5)%0A%20%20%20at%20createInjector%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3751%3A3)%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.18%2F%24injector%2Fmodulerr%3Fp0%3DngRoute%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520Module%2520'ngRoute'%2520is%2520not%2520available!%2520You%2520either%2520misspelled%2520the%2520module%2520name%2520or%2520forgot%2520to%2520load%2520it.%2520If%2520registering%2520a%2520module%2520ensure%2520that%2520you%2520specify%2520the%2520dependencies%2520as%2520the%2520second%2520argument.%250Ahttp%253A%252F%252Ferrors.angularjs.org%252F1.2.18%252F%2524injector%252Fnomod%253Fp0%253DngRoute%250A%2520%2520%2520at%2520Anonymous%2520function%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A1643%253A11)%250A%2520%2520%2520at%2520ensure%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A1567%253A5)%250A%2520%2520%2520at%2520module%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A1641%253A7)%250A%2520%2520%2520at%2520Anonymous%2520function%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A3817%253A11)%250A%2520%2520%2520at%2520forEach%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A320%253A7)%250A%2520%2520%2520at%2520loadModules%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A3811%253A5)%250A%2520%2520%2520at%2520Anonymous%2520function%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A3818%253A11)%250A%2520%2520%2520at%2520forEach%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A320%253A7)%250A%2520%2520%2520at%2520loadModules%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A3811%253A5)%250A%2520%2520%2520at%2520createInjector%2520(http%253A%252F%252Flocalhost%253A12153%252FScripts%252Fangular.js%253A3751%253A3)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3845%3A9)%0A%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A320%3A7)%0A%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3811%3A5)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3818%3A11)%0A%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A320%3A7)%0A%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3811%3A5)%0A%20%20%20at%20createInjector%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A3751%3A3)%0A%20%20%20at%20doBootstrap%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1410%3A5)%0A%20%20%20at%20bootstrap%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1425%3A5)%0A%20%20%20at%20angularInit%20(http%3A%2F%2Flocalhost%3A12153%2FScripts%2Fangular.js%3A1338%3A5)
    

2 个答案:

答案 0 :(得分:1)

您可以使用Google Chrome扩展程序Batarang。我认为它将满足您的一些要求。它扩展了开发人员工具,添加了用于调试和分析AngularJS应用程序的工具。

Here is the link to the blog post and demo video:

答案 1 :(得分:0)

  1. Angularjs提供了错误消息,您刚刚发布了

    错误:[$ injector:modulerr]由于以下原因无法实例化模块 ngRoute

    错误:[$ injector:nomod]模块'ngRoute'不可用!您拼错了模块名称或忘记加载。如果注册模块,请确保将依赖项指定为第二个参数。

  2. 对于调试角度,有AngularJS Batarang插件。它更适用于调试范围值;

  3. 以下是解决问题的关键:模块'ngRoute'不可用!

  4. 我认为角度错误日志非常详细,可帮助您找到解决问题的正确方法

  5. 此处的文档非常有用,ngRoute installation instruction