javascript - 调试 Angular

标签 javascript angularjs debugging

我一直在想,每当 Angular 记录错误时,它都是一堆类似于以下的乱码:

Error: [ng:areq] Argument 'AppController' is not a function, got undefined
http://errors.angularjs.org/1.2.23/ng/areq?p0=AppController&p1=not%20a%20function%2C%20got%20undefined
    at http://localhost/NAME/vendors/angular/angular.js:78:12
    at assertArg (http://localhost/NAME/vendors/angular/angular.js:1509:11)
    at assertArgFn (http://localhost/NAME/vendors/angular/angular.js:1519:3)
    at http://localhost/NAME/vendors/angular/angular.js:7271:9
    at http://localhost/NAME/vendors/angular/angular.js:6663:34
    at forEach (http://localhost/NAME/vendors/angular/angular.js:332:20)
    at nodeLinkFn (http://localhost/NAME/vendors/angular/angular.js:6650:11)
    at compositeLinkFn (http://localhost/NAME/vendors/angular/angular.js:6098:13)
    at compositeLinkFn (http://localhost/NAME/vendors/angular/angular.js:6101:13)
    at compositeLinkFn (http://localhost/NAME/vendors/angular/angular.js:6101:13) 

我怎么知道哪一行我的代码(不是 Angular 源代码)触发了错误?添加断点或 Batarang 没有帮助。

编辑

我对这个特定错误没有问题。在某些情况下,angular 会记录一个行号,例如 Controller.js:1183:48,而在某些情况下则不会。 有什么区别?在后一种情况下,我如何找出我的错误行?

最佳答案

  1. 如果问题是您的某个 Controller 内的运行时错误,您将获得行号。

  2. 如果解释内联内容有问题 {{ like.this() }} 或者指令中的表达式有问题(例如:ng-repeat='foo在 undefinedBar') 或任何其他未在脚本标记或引用中运行的表达式,那么您将从第一次遇到错误的 Angular 框架中获取代码行(通常是指令本身或核心).

  3. 如果您的某个 Controller 由于语法不正确而无法解析,它会告诉您它甚至无法加载模块。如果您的应用程序的设置方式确实存在问题,这也适用,但我认为这个问题适用于您试图在 Controller 或 View 中追踪难以发现的错误的时候。

通常,当我遇到 #2(最常见的挫败感来源)时,我会寻找有关错误类型的线索(例如,如果它告诉我“长度”未定义,则可能是未定义集合)。通常问题与语法错误或我的 Controller 模型未处于我预期的状态有关。

关于javascript - 调试 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26232182/

相关文章:

javascript - angularjs 数据绑定(bind)问题

javascript - 如何在 Chrome 开发工具中找到跟随脚本加载时间线?

javascript - jquery ajax 仅在 IE 中失败

javascript - react-native:更改 <Picker.Item> 标签时 <Picker> 会丢失 selectedValue

javascript - 为什么要更新 _DEFAULT const 变量?

java - Intellij - 如何编辑用于远程调试的 JVM 命令行参数

debugging - Visual Studio 2005 中的调试器选项

local-storage - 在本地存储中保存 Javascript 模块对象

javascript - Preloader在线不淡出

javascript - AngularJS 在指令运行之前通过 AJAX 检索数据