NG-重复内Angularjs NG-通过模型(KEY,VAL)不更新 [英] Angularjs ng-model inside ng-repeat via (key,val) not updating
问题描述
下面是我的工作不演示
<section ng-repeat="t in test">
<div ng-repeat="(key,value) in t">
<div>{{key}}</div>
<input type="text" ng-model="value"/>
</div>
</section>
模型保持不变。如何同步?请注意,数据的结构是重要的。
Model stays the same. How to sync? Please note, structure of data is important.
推荐答案
的 NG-模型
结合将评估在当前范围的前pression。由于 NG-重复
创建一个子范围,这意味着 NG-模型
将寻找一个命名属性值
对孩子的范围。在你的榜样,我们希望它寻找的父 VAL
属性的范围,这是化名为 T
。
The ng-model
binding will evaluate its expression on the current scope. As ng-repeat
creates a child scope, this means that ng-model
will look for a property named value
on the child scope. In your example we'd expect it to look for the val
property on the parent scope, which is aliased to t
.
这是由设计,可以在您的案件由前pression引用父范围 T
被规避。
This is by design and can be circumvented in your case by referencing the parent scope t
in the expression.
code(注意输入元素的结合已经改变):
Code (notice the binding on the input element has changed):
<section ng-repeat="t in test">
<div ng-repeat="(key,value) in t">
<div>{{key}}</div>
<input type="text" ng-model="t[key]"/>
</div>
</section>
当你正在使用的角1.3测试版,这可能是一个错误。
As you're using a beta version of Angular 1.3, this may be a bug.
这篇关于NG-重复内Angularjs NG-通过模型(KEY,VAL)不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!