gopal rao
gopal rao

Reputation: 293

angularjs - what does a :: mean?

In some angular js files, I see below syntax. What does a double colan "::" mean?

<span>{{::x}}</span>
<div>{{::y.z()}}</div>

Upvotes: 4

Views: 2137

Answers (3)

Michel
Michel

Reputation: 28259

This feature is called one-way databinding, and appeared since Angular 1.3. For older versions, there is an equivalent add-on solution called bindonce.

From Angular JS documentation :

An expression that starts with :: is considered a one-time expression. One-time expressions will stop recalculating once they are stable, which happens after the first digest if the expression result is a non-undefined value

Basically, when you write :

{{::x}}

angular will destroy the watcher when x will be defined. The counterpart of it is that x won't be updated anymore in the view if his value changes after that destroy.

Upvotes: 2

Alex
Alex

Reputation: 21766

This syntax is used for one time binding. It provides the ability to render data once and let it persist without being affected by future Model updates. See more details in the link below:

https://www.binpress.com/tutorial/speeding-up-angular-js-with-simple-optimizations/135

Upvotes: 1

squiroid
squiroid

Reputation: 14027

This is a new feature edited in angular js 1.3+

{{ ::title }}

only bind value first time which happens after the first digest if the expression result. Doc

Upvotes: 1

Related Questions