Javascript 角度表达式 {{::}} 中的两个冒号是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34678400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:43:44  来源:igfitidea点击:

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

javascriptangularjsangular-template

提问by J0B

What is the difference between:

有什么区别:

{{::office.name}}

and

{{office.name}}

in angularJS?

在 angularJS 中?

采纳答案by Teo.sk

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

{{::office.name}}语法角度的一次性结合,可用自1.3版
下面是一个不错的博客解释它。

回答by Tushar

One-time bindingFrom Angular Docs.

来自 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, $digestwill 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.

在许多情况下,这些值只需要显示在视图中,并且永远不会从视图或控制器中更新。但是,如果使用双向绑定,$digest将检查每个循环中表达式的任何变化,这是没有必要的。在这些情况下,::应该在表达式之前使用。如上述语句所述,在这种情况下,这比双向绑定语法更有效。



Blog: AngularJS one-time binding syntaxfrom @Todd Motto

博客:来自@Todd Motto 的AngularJS 一次性绑定语法

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 $digestloop. Simple!

简而言之,当我们{{ ::foo }}在 DOM 内部声明一个值时,一旦该值被定义,Angular 就会渲染它,将它与观察者解除绑定,从而减少$digest循环内的绑定量。简单的!