angularjs NG单击默默地吃错误 [英] angularjs ng-click silently eats errors

查看:186
本文介绍了angularjs NG单击默默地吃错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个NG单击像这样:
    NG-点击=越野车()
并没有错误信息单击控制台上生成。

If I have an ng-click like this: ng-click="buggy()" and click on no error message is generated on the console.

这使得它有点棘手调试。

This makes it a bit tricky to debug.

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

Why aren't error messages generated? Anything I can do?

推荐答案

其实,这不是与一些特殊NG-点击,它的角前pressions

Angular expressions

Actually, It's not something special with ng-click, It's the default behavior of angular expressions .

越野车()不与常规的JavaScript评估。它与 $解析评估

buggy() is not evaluated with regular javascript. It is evaluated with $parse.

$解析评估前pressions并返回,将运行对一个范围的功能。

$parse evaluates expressions and returns a function that would run against a scope.

$解析只记录错误。

角前pression评价是宽容的,我想不出任何方式来传递的。

Angular expression evaluation is forgiving , I cannot think of any way to pass it.

一个角度为前pressions理由是宽容的undefined和null有数据绑定做。绑定变量最初可能是未定义或为空时,它们被编译到DOM-人真正明显的例子是,当绑定变量是依赖于一个承诺。该角的团队决定,而不是错误信息雨后春笋般冒出来,直到这种希望解决它最好能够默默地继续。

A rationale for Angular expressions to be forgiving of undefined and null has to do with data binding. Bound variables may initially be undefined or null when they are compiled into the DOM- one really clear example is when the bound variable is dependent on a promise. The Angular team decided that rather than having error messages popping up until that promise is resolved it'd be better to continue silently.

角指导前pressions 的:

它更有意义,显示无非是为了抛出一个异常,如果是
  未定义的(也许我们都在等待服务器的响应,它会
  很快成为定义)。如果ex pression评价并不宽容,我们会
  必须编写杂乱code,例如绑定:
  {{((A || {}); B || {})。ç}}

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}}

另请参见:<一href=\"https://groups.google.com/forum/m/#!topic/angular/HRVOUKEHLFw\">https://groups.google.com/forum/m/#!topic/angular/HRVOUKEHLFw

防爆pressions是JavaScript的类code片段,通常都放在绑定,例如{{EX pression}}。防爆pressions通过的 $解析服务处理。防爆pressions经常发帖使用过滤器来创建一个更加用户友好的格式处理。

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.

这可能是很有诱惑力的思考角度视图前pressions如JavaScript前pressions的,但是这并不完全正确,因为角度不使用JavaScript的eval(),以评估前pressions。你可以把角的前pressions如JavaScript前pressions具有以下区别:

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:


      
  • 属性评估:所有属性的评价是对的范围做了评价,不像在JavaScript中,其中前pressions是针对全局窗口评估

  • 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.

:前pression评价是宽容未定义和空,不像在JavaScript中,在试图评估未定义的属性可以产生的ReferenceError或类型错误

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

无控制流语句:你不能做任何以下的角前pression的:条件语句,循环,或抛出

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

这篇关于angularjs NG单击默默地吃错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆