javascript - Angular 表达式 {{::}} 中的两个冒号是什么意思?

标签 javascript angularjs angular-template

有什么区别:

{{::office.name}}

{{office.name}}

在 angularJS 中?

最佳答案

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).

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


博客:AngularJS one-time binding syntax来自 @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!

关于javascript - Angular 表达式 {{::}} 中的两个冒号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34678400/

相关文章:

angularjs - 如何在 intellij idea 11.1.3 中运行 angularJS 测试?

Angular 4 模板错误 : 'anonymous' does not contain such a member

css - Angular Material -如何设置垫水平内容容器填充0

javascript - 展平嵌套对象数组

javascript - 使用 JQuery 在 Word Web 插件中选择文本

javascript - 如何获取嵌套对象的默认值,包括零作为值

arrays - 是否可以通过包含在另一个数组中来过滤angular.js?

javascript - 将变量传递给 dojo 小部件构造函数

javascript - 当不在路由 url 中时禁用并绕过 Angular 路由

javascript - AngularJS - 将对象传递给属性时动态加载模板URL