-1

reset form angular after saving data successfully

Gopal Meena
  • 107
  • 1
  • 2
  • 8

4 Answers4

1

You can call reset() on the FormGroup instance that represents your form to reset it.

SiddAjmera
  • 38,129
  • 5
  • 72
  • 110
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).

https://stackoverflow.com/a/53522125/5108158

Maximillion Bartango
  • 1,533
  • 1
  • 19
  • 34
0

i got solution form.reset(); // or form.resetForm();

Gopal Meena
  • 107
  • 1
  • 2
  • 8