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

后端 未结 2 671
星月不相逢
星月不相逢 2020-12-24 04:37

What is the difference between:

{{::office.name}}

and

{{office.name}}

in angularJS?

相关标签:
2条回答
  • 2020-12-24 04:40

    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!

    0 讨论(0)
  • 2020-12-24 04:56

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

    0 讨论(0)
提交回复
热议问题