【发布时间】:2021-04-27 05:29:57
【问题描述】:
我有一个需要有一个或多个简单输入字段的响应式表单。所以我正在做一个 *ngFor 来遍历对象数组并可以成功创建标签。我也可以创建输入字段,但我不知道如何跟踪其中输入的值。我需要收集用户输入的输入并将其发送到后端。
我该怎么做? 我做了研究,发现我应该使用一个数组来保存所有可能数量的生成输入字段。但是如何为它创建表单控件。
<form [formGroup]="SignupForm" (ngSubmit)="onSubmit()">
<div class="form-group p-mb-4" *ngFor="let _insertField of actionsetSelected; let i=index">
<label class="formLabel" *ngIf="_insertField" for="userInput">{{_insertField.name}}</label>
<input type="text" class="form-control" id="insertNames" [formControlName]="i">
</div>
<button label="Submit" ></button>
</form>
in my ts:
this.SignupForm = new FormGroup({
'insertNames':new FormArray([])
});
【问题讨论】:
-
查看这个嵌套反应形式的例子...stackblitz.com/edit/…