[英]How do i turn an object array into a formgroup array?
我想使用formbuilder的array函數來使用formcontrol數組。 我有一個現有的自定義對象數組,需要添加到該FormArray
但是它僅將FormGroup
作為參數。 如何將自定義對象數組轉換為FormGroup對象,以便可以將其添加到FormArray中? 我已經嘗試過了:
let formGroupArray: FormGroup[] = [];
for(let i=0; i < account.laborperiods.length; i++){
let formGroup = this.fb.group({
id: this.account.laborperiods[i].id,
beginDate: this.account.laborperiods[i].beginDate,
endDate: this.account.laborperiods[i].endDate,
hours: this.account.laborperiods[i].hours,
account: this.account.laborperiods[i].account
})
formGroupArray.push(formGroup)
}
this.laborPeriodArray = new FormArray(formGroupArray);
但這給了我錯誤"ERROR TypeError: Circular reference in value argument not supported"
那么誰能告訴我如何將自定義對象數組轉換為FormGroup數組? 還是有一種更方便的方法可以將自定義對象數組直接轉換為FormArray?
嘗試:
let formGroupArray:FormArray
for(let i=0; i < account.laborperiods.length; i++){
let formGroup = this.fb.group({
...
})
if (!formGroupArray)
formGroupArray=new FormArray(formGroup);
else
formGroupArray.push(formGroup)
}
//Change this line
this.laborPeriodArray = formGroupArray;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.