如何在AngularJS中调试类型转换错误?

前端之家收集整理的这篇文章主要介绍了如何在AngularJS中调试类型转换错误?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是一个 javascript noob,并试图学习角度.

我有一些简单的angularJS代码,如下所示:

<div ng-controller="todoController">
    <span> temp = {{tempVal()}} </span>
</div>

这个bug很容易,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()行周围.

我尝试在记录错误时设置一个断点并查找callstack,并在$get.Scope.$digest中看到一个捕获的异常,它可以告诉我父作用域id(this.target.$id),随着什么“观察者”(this.length)崩溃,以及之前完成的html元素(this.value)….是最好的方法吗?多么痛苦:(

解决方法

不幸的是,答案是您无法调试此类错误.

好吧,你可以,它被称为“学习角度编译器/ vm并调试它”

这些类型的使用错误没有开发用户友好包装.

猜你在找的Angularjs相关文章