简体   繁体   English

Angular是否会在相同的$ digest循环中重新评估相同的$ watch表达式?

[英]Will Angular reevaluate identical $watch expressions in the same $digest cycle?

If I have a template in the form of: 如果我有以下形式的模板:

<div ng-controller="testCtrl">
    <div ng-if="exFn()"></div>
    <div ng-if="exFn()"></div>
</div>

will the ngController scope call exFn twice per $digest, or will the scope remember that the exFn() expression's new value and use it instead of reevaluating the expression? ngController范围会每个$ digest两次调用exFn ,还是会记住exFn()表达式的新值并使用它而不是重新评估该表达式?

It will call exFn four times. 它将调用exFn四次。 Twice to find out the original value for each watch, then twice again to see if they are stable. 两次找出每只手表的原始值,然后再次两次以查看它们是否稳定。 This makes sense: the function could depend on external state. 这很有意义:该功能可能取决于外部状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM