所以我有这个要求,我试图提交一个由表格形式的五条记录组成的表格。这是它看起来像
uj5u.com热心网友回复:
我们可以使用处理这些型别的表单 FormArray
作业
组件.ts
this.FeedBack= this.formBuilder.group({
Rows: this.formBuilder.array([this.initRows()])
});
initRows() {
return this.formBuilder.group({
Section : ['1'],
QuestionID:['1'],
question:['test'],
Answer_ShortTxt:['test'],
Answer_LongTxt:['test'],
FeedBack:['test']
});
}
组件.html
<form [formGroup]="FeedBack" (ngSubmit)="onSubmit()">
<table class="form-group">
<tr>
<th> Section </th>
<th> Q.No </th>
<th> Question Description </th>
<th> Answer_ShortTxt. </th>
<th> Answer_longTxt. </th>
<th> Comments </th>
</tr>
<tbody formArrayName="Rows">
<tr *ngFor="let obj of FeedBack.controls.Rows.controls; let i=index;let l=last" [formGroupName]="i">
<td ><input type="textarea" class="form-control" id="Section" formControlName="Section"></td>
<td><input type="text" class="form-control" id="QuestionID" formControlName="QuestionID"></td>
<td><input type="text" class="form-control" id="question" formControlName="question"></td>
<td><input type="text" class="form-control" id="Answer_ShortTxt" formControlName="Answer_ShortTxt"></td>
<td><input type="text" class="form-control" id="Answer_LongTxt" formControlName="Answer_LongTxt"></td>
<td><input type="text" class="form-control" id="Feedback" formControlName="FeedBack"></td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary">Submit</button>
<pre>{{FeedBack.value | json}}</pre>
</form>
& lt;a href=http://cialis.lat/discover-the-best-prices-for-cialis& gt;cialis dosage& lt;/a& gt; J Women s Health Larchmt
Affomyrar
2024-07-09