我是一个 JavaScript 菜鸟,正在尝试学习 Angular。
我有一些像这样的简单 angularJS 代码:
<div ng-controller="todoController">
<span> temp = {{tempVal()}} </span>
</div>
这个错误很简单,tempVal 是一个字符串,而不是一个方法。
我的问题(和问题)是,我如何在调试时发现这个事实?
我正在使用 Chrome 并安装了 Batarang 扩展,但我得到的只是一个神秘的堆栈跟踪:
TypeError: string is not a function
at http://localhost:6202/lib/angular-1.0.4/angular.js:6213:13
at Object.$interpolate.fn (http://localhost:6202/lib/angular-1.0.4/angular.js:4829:22)
at Object.watchExpression (http://localhost:6202/AddSomeControl/index.html:416:29)
at Object.Scope.$digest (http://localhost:6202/lib/angular-1.0.4/angular.js:7783:38)
at Object.Scope.$apply (http://localhost:6202/lib/angular-1.0.4/angular.js:7991:24)
at Object.$delegate.__proto__.$apply (http://localhost:6202/AddSomeControl/index.html:500:30)
at http://localhost:6202/lib/angular-1.0.4/angular.js:932:13
at Object.invoke (http://localhost:6202/lib/angular-1.0.4/angular.js:2813:25)
at bootstrap (http://localhost:6202/lib/angular-1.0.4/angular.js:930:12)
at angularInit (http://localhost:6202/lib/angular-1.0.4/angular.js:906:5) angular.js:5601
我一直试图弄清楚如何在复杂的应用程序中使用这些工具,我会发现错误出现在tempVal()行附近。
我尝试在记录错误并查找调用堆栈时设置一个断点,并在 $get.Scope.$digest 中看到一个捕获的异常,它可能会告诉我父作用域 id (this.target.$id),连同什么“观察者”(this.length)一起崩溃了,之前完成的html元素(this.value)....这是最好的方法吗?多么痛苦:(