Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do bindings nested inside of a lazy one-time ng-repeat binding bind just once?

My understand is that in the following code, both bindings will lazily bind only once:

<li ng-repeat="item in ::items">{{::item.name}}</li>

However, in the following case will {{item.name}} be updated every digest?

<li ng-repeat="item in ::items">{{item.name}}</li>

And how does one-time binding effect nested ng-repeats ?

<li ng-repeat="item in ::items">
  <span ng-repeat="thing in item.things">{{thing.name}}</span>
</li>
like image 207
Gil Birman Avatar asked May 28 '14 05:05

Gil Birman


1 Answers

Scenario 1:

<li ng-repeat="item in ::items">{{::item.name}}</li>

Both expressions will be one-time bound. Adding an item or changing an existing item's name will not be reflected.

Demo: http://plnkr.co/edit/53r8FCmcNK4MmM6Uzxp2?p=preview

Scenario 2:

<li ng-repeat="item in ::items">{{item.name}}</li>

First expression will be one-time bound. Adding an item will not be reflected. Changing an existing item's name will be reflected.

Demo: http://plnkr.co/edit/52wTEb8ze2FKRDDcS9Ow?p=preview

Scenario 3:

<li ng-repeat="item in ::items">
  <span ng-repeat="thing in item.things">{{thing.name}}</span>
</li>

First expression will be one-time bound. Adding new item will not be reflected. Adding a new thing and changing existing thing's name will be reflected.

Demo: http://plnkr.co/edit/HkObhkJtUnFEHBAzFUmN?p=preview

like image 176
tasseKATT Avatar answered Nov 13 '22 18:11

tasseKATT