简体   繁体   中英

ng-repeat one-time binding inheritance?

If I have an ng-repeat directive iterating through a list of lists via a one-time binding, does a nested ng-repeat through each of the inner lists also need a one-time binding, or is that redundant?

<div ng-repeat="list in ::$ctrl.lists">
  <span ng-repeat="item in list">{{item}}</span>
</div>

Do I need to change the inner ng-repeat to item in ::list ? $ctrl.lists will never change in any manner.

It is specify nowhere that is is inherit, event if you have bind the array, object inside the array can still change, so it is better to put '::' for the span loop too.

http://jsfiddle.net/vw2fjxys/64/

var a = [1,2,3]
    setTimeout(function(){
    console.log(2)
        a.length = 2
      $scope.$apply();
    },3000)
$scope.lists = [a];

You can see on the exemple after 2 second that with :: it is not recalculated for the inner loop but without it is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM