What is the meaning of :: in Angular? [duplicate]

扶醉桌前 提交于 2019-12-13 09:26:48

问题


I saw this partial code in an ng-repeat directive

<div ng-repeat="image in images">
    <img ng-src="{{::image.src}}"/>
</div>

Not sure if it's related to the ng-repeat directive.

The page looks the same with or without it but I'm curious what it is.


回答1:


This synthax is use for one-time binding in AngularJS:

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

See the related Plunker.




回答2:


That is the notation for one-time binding. It's commonly used with ngRepeat for performance reasons.

See https://docs.angularjs.org/guide/expression




回答3:


the :: in angular is to bind the data in the template once so Angular does not set a watcher on the field. You'll want to this if you don't expect the data to change as it can help with performance by limiting the number of watchers on the page, here's a link with more info and other performance tips:

http://www.befundoo.com/blog/optimizing-ng-repeat-in-angularjs/



来源:https://stackoverflow.com/questions/43187670/what-is-the-meaning-of-in-angular

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