anglejs ng-click静默地吃错误

如果我有这样的ng点击:
NG-点击= “越野车()”
并单击,控制台上不会生成错误信息。

这使得调试有点棘手。

为什么不生成错误消息?我能做什么?

角度表达

实际上,这不是特别的,点击ng,这是角度表达式的认行为。

buggy()不使用常规javascript进行评估。它使用$ parse进行评估。

$ parse计算表达式并返回一个可以对范围运行的函数

$ parse只有当表达式无效时才会记录错误

角度表达评估是宽容的,我想不出有什么办法通过。

为什么表达是宽恕的?

Angular表达式被原谅的未定义和null的理由与数据绑定有关。当绑定变量被编译到DOM中时,绑定变量可能最初未定义或为空,当绑定变量取决于承诺时,真正明确的示例就是绑定变量。角色团队决定,除非出现错误信息,直到该承诺得到解决,否则最好继续地继续。

Angular guide to expressions

It makes more sense to show nothing than to throw an exception if a is
undefined (perhaps we are waiting for the server response,and it will
become defined soon). If expression evaluation wasn’t forgiving we’d
have to write bindings that clutter the code,for example:
{{((a||{}).b||{}).c}}

另请参见:https://groups.google.com/forum/m/#!topic/angular/HRVOUKEHLFw

Angular expressions

Expressions are JavaScript-like code snippets that are usually placed in bindings such as {{ expression }}. Expressions are processed by the $parse service. Expressions are often post processed using filters to create a more user-friendly format.

Angular Expressions vs. JS Expressions

It might be tempting to think of Angular view expressions as JavaScript expressions,but that is not entirely correct,since Angular does not use a JavaScript eval() to evaluate expressions. You can think of Angular expressions as JavaScript expressions with following differences:

  • Attribute Evaluation: evaluation of all properties are against the scope doing the evaluation,unlike in JavaScript where the expressions are evaluated against the global window.

  • Forgiving: expression evaluation is forgiving to undefined and null,unlike in JavaScript,where trying to evaluate undefined properties can generate ReferenceError or TypeError.

  • No Control Flow Statements: you cannot do any of the following in angular expression: conditionals,loops,or throw.

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...