我无法将Angular Reactive Form组添加到FormArray。请参见下面的代码。
Home.ts
ngOnInit(){
this.myForm = this.formBuilder.group({
items: this.formBuilder.array([])
});
this.addItemsToForm();
console.log("form----- "+JSON.stringify(this.myForm.value))
}
addItemsToForm(){
const arrayControl = <FormArray>this.myForm.get('items')
arrayControl.push(
this.formBuilder.group({
hazardStatus: ["dsad"],
})
)
}
Home.html
<form [formGroup]="myForm">
<div formArrayName="items">
<div *ngFor="let model of items; let k = index;" no-padding style="background-color:transparent">
{{items.length}}
<div [formGroupName]="k">
{{items.length}}
<ion-item>
<ion-label item-left stacked>
{{model.hazardStatus}}
</ion-label>
</ion-item>
</div>
</div>
</div>
</form>
我的日志显示表单值{"items":[{"hazardStatus":"dsad"}]}
但是,表单没有显示。