我建立一個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