I am Using the Angular Reactive forms and material-ui,and using the mat-tab select element, I want to patch the value on tab Change ,but on ngOnint I am already patch the value for 1 tab but as i rendering the same component on another tab, I want to change the value of formGroup another tab
Please find the screenshot of the tabs which is to be done
On ngOninit
I am patching initially the la(life assured) and sp(spouse) form values
if (clientAs = 'la' && this.merActiveDataLa == '') {
this.merActiveDataLa = merData
} else if (clientAs = 'sp' && this.merActiveDataSp == '') {
this.merActiveDataSp = merData
}
if (merData) {
this.merFormGroup.patchValue(this.merActiveDataLa);
}
On tabChanged
method I am using this concept’
tabchanged(event, forcomponentSection = undefined) {
// console.log(event)
if (forcomponentSection) {
this.selectedTabForLA = event;
console.log("Tab Valuee ",this.selectedTabForLA);
if (this.selectedTabForLA == 1) {
if (this.merActiveDataSp) {
this.merFormPayload.patchValue(this.merActiveDataSp)
console.log("I am hereeee22222",this.merFormPayload);
}
this.clientAs = 'sp'
} else {
if (this.merActiveDataLa) {
this.merFormPayload.patchValue(this.merActiveDataLa)
console.log("I am hereeee33333",this.merFormPayload);
}
this.clientAs = 'la'
}
} else {
this.selectedTab = event;
}
}
Please helps any comments and suggestions would be in advances.