Reputation: 327
I have a angular reactive form and some of the fields in the form are pre populated. I want to implement a 'Cancel' button that will reset all the changes to the form except the data that were pre populated when page was loaded. I tried the following but it resets the whole form:
resetForm() {
this.myForm.reset();
}
is there a way to reset only the current changes instead of resetting the whole form?
Upvotes: 1
Views: 780
Reputation: 4182
You can do it with patchValue
resetForm() {
this.myForm.patchValue(initialValue);
}
initialValue
is a object that holds populated values.
Upvotes: 3