One Time Binding

less than 1 minute read

TIL that angular 1.3 and onwards has a one-time-bind option to pass to interpolated expressions, which tells angular that the data is not expected to change.

The one-time-bind option tells angular not to add a watcher to the interpolated property, effectively disabling 2-way binding for the property. If you know a $scope property is not expected to change during the lifetime of the view, why waste the extra time during the $digest() cycle to dirty-check the property?

Example:

<!-- Normal 2-way binding (creates a watcher on $scope.name) -->
<span>Hello,  {{ name }} </span>

<!-- one-time binding (no watcher created) -->
<span>Hello,  {{ ::name }} </span>

The double semicolon :: lets angular know that it should do a one time binding of the scope property to the template. If $scope.name changes in the second situation above, the change will not be reflected in the template.

Another reason to upgrade to angular 1.3!

Leave a Comment