ng-repeat中的角度js - ng-模型

时间:2015-09-06 17:36:37

标签: html angularjs angularjs-ng-repeat angular-ngmodel

ng重复中的'ng-model name'不同?可能吗?

<div  ng-repeat="todo in todos">
   <input type="text" ng-model="tag">  
   <button type="submit"ng-click="addTodo(todo._id)">Add</button>
</div>

在这种情况下,有一些重复的待办事项(基于待办事项json数据)将在前端显示

我的问题:我在任何输入字段上键入的内容,所有输入字段显示相同的数据

我需要在每个输入字段上使用不同的ng-model名称,我想这就是ng-model="tag($index)"

3 个答案:

答案 0 :(得分:2)

可能如下

<div  ng-repeat="todo in todos">
   <input type="text" ng-model="tag[todo]">  <--todo.key-->
   <button type="submit"ng-click="addTodo(todo._id)">Add</button>
</div>

答案 1 :(得分:2)

您可以将新创建​​的模型放在标记数组中$index,同时在tag内声明模型,您应该使用数组表示法[]而不是()

ng-model="tag($index)" 

应该是

ng-model="tag[$index]"

<强>标记

<div  ng-repeat="todo in todos">
   <input type="text" ng-model="tag[$index]">  
   <button type="submit"ng-click="addTodo(todo._id)">Add</button>
</div>

答案 2 :(得分:1)

你可以这样做:

 <input type="text" ng-model="todo.tag">  
相关问题