我建立一个SPA,人们可以在添加表行使用$索引按钮点击:为NG-模型
<!-- Table -->
<table>
<tr>
<th>Lieferscheinnummer</th>
<th>Stück</th>
</tr>
<tr ng-repeat="position in positions">
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
</table>
<!-- button -->
<span ng-click="addPosition()"></span>
控制器
$scope.positions = ['1'];
$scope.addPosition = function(){
$scope.positions.push($scope.positions.length + 1);
}
现在我要申请一个唯一的ng-model
到每个行的每个<td>
,以便将给定的输入发送到我的数据库。
我搜索了一个解决方案,并绊倒了ng-repeat
的$index
。 不幸的是,$index
似乎是元素属性是不可用:
<tr ng-repeat="position in positions">
<td><input type="text" ng-model="{{$index +1}}"></td> <!-- does not work -->
<td><input type="text"></td>
</tr>
我将如何运用独特ng-model
每一行,而使用ng-repeat
?
这太好了,非常感谢! – Sprottenwels