【发布时间】:2021-12-02 12:28:51
【问题描述】:
我有来自表单(模态)的数据,我必须将其修补到另一个表单(折叠)中。 这是数据的来源。
formInitializer() {
this.agrmntsForm = this.formBuilder.group({
sales_price: new FormControl(''),
closing_cost_support: new FormControl(''),
financing: new FormControl(''),
contract_date: new FormControl(''),
inspection_period: new FormControl(''),
closing_date: new FormControl(''),
contacts: this.formBuilder.array([]),
});
}
这是我试图将数据修补到的表单:
mainFormInitializer() {
this.mainForm = this.formBuilder.group({
agreements: this.formBuilder.array([]),
});
}
目前我正在修补第一个表单(模态)提交的数据。它确实修补了第一个数组,但我很难修补其中的嵌套表单数组。
这是修补表单的代码:
patchControls(formValue) {
const control = <FormArray>this.mainForm.get('agreements');
// const control2 = <FormArray>this.mainForm.get('contacts');
console.log('form here', this.mainForm.controls.contacts);
for (const obj of formValue) {
const addrCtrl = this.createAgreementsGroup();
const contactsCtrl = this.createContactsCtrl();
addrCtrl.patchValue(obj);
control.push(addrCtrl);
}
}
我已将代码添加到stackblitz
【问题讨论】:
-
您是否只想将模型生成的
this.agrmntsFormForm Group 添加到this.mainForm的agreements数组中? -
是的。模态生成的表单包含
agreements(组),它还包含contacts的数组。我想要我的mainForm协议数组中的这两件事,以便我获得协议详细信息以及与特定agreement关联的contacts -
您是否检查过其他问题,例如:stackoverflow.com/q/59553622/5468463 或 stackoverflow.com/q/59588933/5468463。有很多
-
是的,我确实检查了这个问题。它似乎没有解决我的问题。当我尝试访问控件时,它说控件未定义。
标签: angular angular-reactive-forms angular2-forms angular-forms formarray