I have data coming from a form(modal) that I have to patch into another form (collapse). this is the form where the data is coming from.
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([]),
});
}
and this is the form I am trying to patch the data into:
mainFormInitializer() {
this.mainForm = this.formBuilder.group({
agreements: this.formBuilder.array([]),
});
}
currently I am patching the data on the first form (modal) submit. and it does patch the first array but I am having a tough time patching the nested form Array inside it.
this is the code for patching the form :
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);
}
}
I have added the code to stackblitz
this.agrmntsFormForm Group intothis.mainForm'sagreementsarray?agreements( the group ) and it contains an array ofcontactsas well. I want both of those things inside mymainFormagreements array, so that the I get both the agreement details as well as thecontactsassociated with that specificagreement