问题
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