角偷懒一次为前pressions结合 [英] Angular lazy one-time binding for expressions

查看:130
本文介绍了角偷懒一次为前pressions结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AngularJS从此版本1.3.0-beta.10一个新的功能:懒一次性绑定

简单的前pressions可与 pfixed $ P $ :: ,告诉角度停止前pression看后首次评估。给出的常见的例子是这样的:

 < D​​IV> {{:: user.name}}< / DIV>

有没有类似的语法为前pressions像下面的人?

 < D​​IV NG-IF =user.isSomething&放大器;&安培; user.isSomethingElse>< / DIV>
< D​​IV纳克级={classNameFoo:user.isSomething}>< / DIV>


解决方案

是的。您可以preFIX每前pressions与,甚至鸡舍 ngIf ngClass

 < D​​IV NG-IF =::( user.isSomething&放大器;&安培; user.isSomethingElse)>< / DIV>
< D​​IV纳克级={:: 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屋!

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