reset form angular after saving data successfully
Asked
Active
Viewed 309 times
-1
-
which form you are using template driven or Model-Driven? – Sneha Pawar Jan 14 '19 at 12:47
-
reactive form i am using – Gopal Meena Jan 14 '19 at 12:50
4 Answers
1
If you are using Template Driven Form :
HTML code
<form #myForm="ngForm" (submit)="resetForm(myForm)"> ... </form>
TS Code
resetForm(form: NgForm){
form.reset(); // or form.resetForm();
}
In Reactive Form
HTML code
<form (ngSubmit)="resetForm()">
</form>
TS code
// Declare your form
myform: FormGroup;
resetForm() {
if (this.myform.valid) {
this.myform.reset();
}
}

Sneha Pawar
- 1,097
- 6
- 14
1
The default .reset() method will wipe the inputs but it will not correctly reset the validators. If you're using validators, see this solution (or the main solution to the question if resetting after a submit).

Maximillion Bartango
- 1,533
- 1
- 19
- 34