不要嵌套绑定内慵懒一次NG重复绑定绑定的只有一次? [英] Do bindings nested inside of a lazy one-time ng-repeat binding bind just once?

查看:143
本文介绍了不要嵌套绑定内慵懒一次NG重复绑定绑定的只有一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,在以下code,两者绑定将​​ 懒洋洋地绑定只有一次

 <李NG重复=项::项目> {{:: item.name}}< /李>

但是,在以下情况下的 {{} item.name} 每摘要更新?

 <李NG重复=项::项目> {{item.name}}< /李>

如何一次性约束力嵌套的 NG-重复取值

 <李NG重复=项::项目>
  <跨度NG重复=,在item.things事> {{thing.name}}< / SPAN>
< /李>


解决方案

方案1:

 <李NG重复=项::项目> {{:: item.name}}< /李>

这两个前pressions将被绑定一次。添加项目或更改现有项目的名称将无法体现。

演示: http://plnkr.co/edit/53r8FCmcNK4MmM6Uzxp2?p=$p$pview

情景2:

 <李NG重复=项::项目> {{item.name}}< /李>

第一八佰伴pression将被绑定一次。添加项目不会被反映出来。更改现有项目的名称将有所体现。

演示: http://plnkr.co/edit/52wTEb8ze2FKRDDcS9Ow?p=$p$pview

场景3:

 <李NG重复=项::项目>
  <跨度NG重复=,在item.things事> {{thing.name}}< / SPAN>
< /李>

第一八佰伴pression将被绑定一次。添加新项目不会被反映出来。添加一个新的东西,改变现有的东西的名字就会体现出来。

演示: http://plnkr.co/edit/HkObhkJtUnFEHBAzFUmN?p=$p$pview

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>

解决方案

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

这篇关于不要嵌套绑定内慵懒一次NG重复绑定绑定的只有一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆