1 .On 按钮单击创建一个创建表单组并添加到父表单组中的表单数组的函数
- 对于这样的放置键值
let r=this.fb.group({mvl:"keey",sec:"val"});
- 将您的输入标记为只读以使其不可食用
foo:FormGroup
constructor(public fb:FormBuilder) {
this.foo=this.fb.group({
string :"",
number:0,
common1:this.common,
common2:this.common,
multi:this.fb.array([])
});
}
add()
{
let r=this.fb.group({mvl:"keey",sec:"val"});
(this.foo.get("multi") as FormArray).push(r);
}
在你的表单里面放这样的html
<div formArrayName="multi">
<div *ngFor="let el of multiForm;let i=index" [formGroupName]="i">
<input type="text" matInput placeholder="mvl{{i}}" formControlName="mvl">
<input type="text" matInput placeholder="sec{{i}}" formControlName="sec">
</div>
<div (click)="add()">add</div>
</div>