使用角度的反应式形式在数组内修补数组



我正在尝试在rowsFormArray中显示detailsFormArray。我需要帮助,因为我无法显示detailsFormArray 的数据。我只知道如何显示rowsFormArray,但detailsFormArray对我来说要困难得多。这是我在下面尝试的内容。 请参阅我创建的这个堆栈闪电战文件。

点击此链接

谢谢。

patchValues() {
let rows = this.myForm.get('rows') as FormArray;
this.orders.sales.deliveries.forEach(item => {
rows.push(this.fb.group({
delivery_number: item.delivery_number,
id: item.sales_delivery_id,
details: this.fb.array([this.patchDetails(item.details, item.details.length-1)])
}));
});
}
patchDetails(item_details, i) {
let rows =  (<FormArray>this.myForm.controls['rows']).controls[i]['controls']['details'] as FormArray
item_details.forEach(item => {
rows.push(this.fb.group({
sku: item.ingredient_name
}));
});
console.log(rows)
}
details: this.fb.array([this.patchDetails(item.details, item.details.length-1)])

您在创建表单数组时调用patchDetails,但该方法不返回任何内容,而是可以修改patchDetails以返回FormArray,如下所示

patchValues(): void {
let rows = this.myForm.get('rows') as FormArray;
this.orders.sales.deliveries.forEach(item => {
rows.push(this.fb.group({
delivery_number: [item.delivery_number],
id: [item.sales_delivery_id],
details: this.patchDetails(item.details)
}));
});
}

patchDetails(item_details: any[]): FormArray {
let detailsFormArray: FormArray = new FormArray([]);
item_details.forEach(item => detailsFormArray.push(this.fb.group({
sku: [item.ingredient_SKU],
name: [item.ingredient_name]
})));
return detailsFormArray;
}

斯塔克闪电战

相关内容

  • 没有找到相关文章

最新更新