加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

anglejs ng-click静默地吃错误

发布时间:2020-12-17 08:13:22 所属栏目:安全 来源:网络整理
导读:如果我有这样的ng点击: NG-点击= “越野车()” 并单击,控制台上不会生成错误信息。 这使得调试有点棘手。 为什么不生成错误消息?我能做什么? 角度表达 实际上,这不是特别的,点击ng,这是角度表达式的默认行为。 buggy()不使用常规javascript进行评估。
如果我有这样的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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读