Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
834 views
in Technique[技术] by (71.8m points)

angularjs - 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...