HTML:
<form [formGroup]="locationForm" #myForm="ngForm" class="formContainer">
<div class="buttonContainer">
<section class="btn1">
<button
(click)="addAnotherMethod()"
mat-raised-button
color="primary"> Add another method </button>
</section>
<section>
<button
(click)="addAnotherLocation()"
mat-raised-button
color="primary"> Add another location </button>
</section>
</div>
.TS File
@ViewChild('myForm') currentLocationForm;
addAnotherLocation(): void{
if(this.locationForm.valid){
//send data to redux
}))
}
this.currentLocationForm.resetForm()
}
addAnotherMethod: void {
if(this.locationForm.valid){
//send data to redux
}))
}
this.currentLocationForm.resetForm()
}
With the above code I'm able to reset the form after the data is sent to redux,but after reset, the validation error messages in the new form comes up saying to fill the required fields. I need help in using the correct method in resetting this form and clearing validations when new form is shown. I may be also using wrong method to call two button functions. Thank you.