首页 > 有关angularjs中ng-repeat循环中ng-model的问题

有关angularjs中ng-repeat循环中ng-model的问题

我是angularjs的入门选手,现在在项目中遇见这样的一个问题 在angularjs中ng-repeat循环一个表单内容, 产生的多个表单内都使用相同名字的ng-model内容,根据angular的双向数据绑定的原因 改一个内容就会更新全部的,我想知道有没有好的解决方案。请各位大牛们给予解答。

循环代码

这是输入后的效果


不会的,ng-repeat会对每个数组生成一个$$hashKey,会定位到每个数组,所以改一个不会更新全部


Texeure是在全局scope下面的,而repeat里面有自己的scope,这个scope“继承”全局的scope。
input的model应该使用repeat里的scope有效的变量。
你可以这样写

<div ng-init="Texture = [{value : '牙膏',price : 10},{value : '牙刷',price : 1}]">
    <div ng-repeat="item in Texture">
        {{item.value}}:{{item.price}}
        <input type="text" ng-model="item.price"/>
    </div>
</div>
【热门文章】
【热门文章】