实际上,这不是特别的,点击ng,这是角度表达式的默认行为。
buggy()不使用常规javascript进行评估。它使用$ 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
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.
原文地址:https://www.jb51.cc/angularjs/144519.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。