anglejs ng-click静默地吃错误

前端之家收集整理的这篇文章主要介绍了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.

猜你在找的Angularjs相关文章