NG-重复内Angularjs NG-通过模型(KEY,VAL)不更新 [英] Angularjs ng-model inside ng-repeat via (key,val) not updating

查看:128
本文介绍了NG-重复内Angularjs NG-通过模型(KEY,VAL)不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的工作不演示

<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屋!

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