Dror Cohen
Dror Cohen

Reputation: 125

meaning of :: in angular formly

i'm trying to learn how to work with angular firmly and i'm having trouble understanding some of the syntax used in the guides and examples on the official website. when defining a button form control i saw this template:

<div><button type="{{::to.type}}" class="btn btn-{{::to.btnType}}" ng-click="onClick($event)">{{to.text}}</button></div>

my question is: what is the meaning of "::" before the "to.type" and "to.btnType"? how is it being used? how is that different from defining it like this:

<a ng-class="{'btn-primary': to.isPrimary, active: to.isActive}" class="btn, btn-default"/>

Upvotes: 8

Views: 440

Answers (2)

Jamiec
Jamiec

Reputation: 136094

It is a one-time binding expression, it stops the proliferation of watchers which can often cause performance issues.

Here is some useful reading: http://blog.thoughtram.io/angularjs/2014/10/14/exploring-angular-1.3-one-time-bindings.html

Upvotes: 5

jeerbl
jeerbl

Reputation: 7867

This is the one-time binding expression.

In your case, when to.type will have a value set, it will be updated in the HTML template. Then, if the value to.type changes again, the HTML template won't be updated with the new value.

More information can be found on AngularJS website at https://docs.angularjs.org/guide/expression#one-time-binding.

Upvotes: 0

Related Questions