1
私はng-repeat-start
のテーブルを持っています。AngularJS:ng-form + ng-repeat-start
各については、ng-form
を作成して各アイテムを検証し、アイテムごとにエラーメッセージを生成しています。
ng-form
にng-repeat-start
とng-repeat-end
の間で生成されたすべての行からアクセスできるように、HTMLを構造化する正しい方法は何ですか?
<ng-form name="allItemsForm" novalidate>
<table>
<thead>
<tr>
<th>Items</th>
</tr>
</thead>
<tbody>
<tr ng-form="itemForm" ng-repeat-start="item in ctrl.items">
<td>
<input ng-model="item.name" name="name" required />
</td>
</tr>
<tr>
<td>
<textarea ng-model="item.comment" name="comment" required></textarea>
</td>
</tr>
<tr>
<td>Error for name: {{ itemForm.name.$invalid }}</td>
</tr>
<tr ng-repeat-end>
<td>Error for comment: {{ itemForm.comment.$invalid }}</td>
</tr>
</tbody>
</table>
<button type="submit" ng-disabled="allItemsForm.$invalid">
SUBMIT
</button>
</ng-form>
例:https://jsfiddle.net/7163osn2/4/
「NG-フォームはすべての行からアクセスできるように」、あなたが達成するために何をしたいですか:元の質問での私の例に
更新? – shershen
@shershen私は例を追加しました。最初の数行に表示されるエラーに関する情報を保持するために余分の行を使用したいと思います。 –
'' '