One-time binding in Angular

To speed up the $digest loop, it is a good practise to create as low watchers as possible. Sometimes, a template renders some data that won’t change over time. Thus, there is no need to check if the data has changed during the $digest loop. There are great modules to accomplish that, for example bindonce or angular-once. However, from version 1.3.10, one-time binding became the core feature of the Angular.

Usage is simple, just put ‘::’ on the beginning of your Angular expression.

Of course, any expression can by one-time binded, like this one

In previous example, is it obvious that user roles shouldn’t change during the application is running, in this concrete example, it could be administrator, user or guest.

The great thing is, the value is evaluated until it became something other than undefined or null (libraries mentioned above are implementing this also). If the value is undefined no more, the value is rendered and the watcher is deregistered. This is a thing, because you can render the template before the data are fetched (with some http request), and when they are ready, the template gets updated (in $digest loop, of course, but only once).

Official documentation of this feature can be found here (scroll to one-time binding).