angularjsangularjs-ng-repeatone-time-binding

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.


Solution

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