角偷懒一次为前pressions结合 [英] Angular lazy one-time binding for expressions
问题描述
AngularJS从此版本1.3.0-beta.10一个新的功能:懒一次性绑定。
简单的前pressions可与 pfixed $ P $ ::
,告诉角度停止前pression看后首次评估。给出的常见的例子是这样的:
< DIV> {{:: user.name}}< / DIV>
有没有类似的语法为前pressions像下面的人?
< DIV NG-IF =user.isSomething&放大器;&安培; user.isSomethingElse>< / DIV>
< DIV纳克级={classNameFoo:user.isSomething}>< / DIV>
是的。您可以preFIX每前pressions与:
,甚至鸡舍 ngIf
或 ngClass
:
< DIV NG-IF =::( user.isSomething&放大器;&安培; user.isSomethingElse)>< / DIV>
< DIV纳克级={:: classNameFoo:user.isSomething}>< / DIV>
其实,<一个href=\"https://github.com/angular/angular.js/blob/cee429f0aaebf32ef1c9aedd8447a48f163dd0a4/src/ng/parse.js#L1027\">the code 简单地检查,在恩pression前两个字符是:
以激活一次性绑定(然后删除它们,从而括号甚至没有必要)。其他一切不变。
AngularJS has a new feature since the version 1.3.0-beta.10: the "lazy one-time binding".
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
:
<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.
这篇关于角偷懒一次为前pressions结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!