8

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"/>
Dror Cohen
  • 125
  • 7

2 Answers2

5

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

jeerbl
  • 7,537
  • 5
  • 25
  • 39
Jamiec
  • 133,658
  • 13
  • 134
  • 193
0

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.

jeerbl
  • 7,537
  • 5
  • 25
  • 39