我有一个带有 FormGroup
控件的 FormArray
,其中填充了 FormGroup
个实例
someForm = this.fb.group({
days: this.fb.array([
this.fb.group({
description: ['']
})
])
})
另外,我有一个用于这个数组的 getter
get days(): FormArray {
return this.someForm.get('days') as FormArray;
}
当我尝试遍历 FormArray
并将其分配给 [formGroup]
指令时,如 this article
<div *ngFor="let day of days.controls">
<ng-container [formGroup]="day">
...
我要了
error TS2740: Type 'AbstractControl' is missing the following properties from type 'FormGroup': controls, registerControl, addControl, removeControl, and 3 more.
答案 0 :(得分:2)
我在 this article 中找到了一种解决方法,通过 FormGroups
遍历 index
,例如:
<div *ngFor="let day of days.controls; let i=index">
<ng-container [formGroupName]="i">
...