Sam Claus
Sam Claus

Reputation: 1989

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.

Upvotes: 0

Views: 65

Answers (1)

bormat
bormat

Reputation: 1379

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.

Upvotes: 1

Related Questions