简体   繁体   English

表达式的角度懒惰一次性绑定

[英]Angular lazy one-time binding for expressions

AngularJS has a new feature since the version 1.3.0-beta.10: the "lazy one-time binding" . 自1.3.0-beta.10版本以来,AngularJS有一个新功能: “懒惰的一次性绑定”

Simple expressions can be prefixed with :: , telling angular to stop watching after the expression was first evaluated. 简单的表达式可以以::为前缀,告诉角度在首次评估表达式后停止观看。 The common example given is something like: 给出的常见示例如下:

<div>{{::user.name}}</div>

Is there a similar syntax for expressions like the following ones? 是否有类似以下表达式的语法?

<div ng-if="user.isSomething && user.isSomethingElse"></div>
<div ng-class="{classNameFoo: user.isSomething}"></div>

Yes. 是。 You can prefix every expressions with :: , even the ones in ngIf or ngClass : 你可以在每个表达式前加上:: ,甚至是ngIfngClass

<div ng-if="::(user.isSomething && user.isSomethingElse)"></div>
<div ng-class="::{classNameFoo: user.isSomething}"></div>

Actually, the code simply checks that the two first characters in the expression are : in order to activate the one-time binding (and then removes them, thus the parenthesis aren't even needed). 实际上, 代码只是检查表达式中的两个第一个字符是:为了激活一次性绑定(然后删除它们,因此甚至不需要括号)。 Everything else remains the same. 其他一切都是一样的。

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

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