What does two colons inside an angular expression {{::}} mean?

一世执手 提交于 2019-11-28 18:07:19

问题


What is the difference between:

{{::office.name}}

and

{{office.name}}

in angularJS?


回答1:


The {{::office.name}} syntax is Angular's One-Time binding, available since version 1.3
Here's a nice blog explaining it.




回答2:


One-time binding From Angular Docs.

An expression that starts with :: is considered a one-time expression. One-time expressions will stop recalculating once they are stable, which happens after the first digest if the expression result is a non-undefined value (see value stabilization algorithm below).

In many situations, the values need to be only shown in the view and are never going to update from view or controller. However, if two-way binding is used, $digest will check for any changes in the expression in each cycle, which is not necessary. In these cases, :: should be used before expression. As stated in the above statement, this is more efficient than two-way binding syntax for such cases.


Blog: AngularJS one-time binding syntax from @Todd Motto

In a nut shell, when we declare a value such as {{ ::foo }} inside the DOM, once this value becomes defined, Angular will render it, unbind it from the watchers and thus reduce the volume of bindings inside the $digest loop. Simple!



来源:https://stackoverflow.com/questions/34678400/what-does-two-colons-inside-an-angular-expression-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!