Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  16] [ 6]  / answers: 1 / hits: 20402  / 10 Years ago, sat, may 31, 2014, 12:00:00

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>

More From » angularjs

 Answers
15

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.


[#70778] Thursday, May 29, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rocioblancac

Total Points: 699
Total Questions: 96
Total Answers: 108

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
;