1

Today I was looking at some angular code and was surprised to see this operator. Not sure what this operator does? Could somebody provide more information on the special operator :: ? I have neither encountered this operator before nor seen it in AngularJS docs.

project-id="{{::vm.projectId}}"

neelmeg
  • 2,459
  • 6
  • 34
  • 46
  • 1
    that's the one time binding - http://blog.thoughtram.io/angularjs/2014/10/14/exploring-angular-1.3-one-time-bindings.html – MaKCbIMKo Nov 16 '16 at 17:02

1 Answers1

4

Using that syntax will save on resources by not spawning a watcher for the variable.

When you put a variable in a template using the double-curly syntax ({{...}}) Angular will generally spawn a watcher for that variable. This means that whenever changes are made to that variable in your Angular code the front-end will reflect that change.

Sometimes this over-eager watcher syntax isn't what you want, though. For instance, you may have a variable that you know will not change, or a variable that will change, but you don't want that change reflected immediately. This is why you will sometimes see the {{::my-var}} syntax, as it doesn't spawn a watcher.

watzon
  • 2,401
  • 2
  • 33
  • 65