Home  >  Forum  >  Angular
Post New Query

Angular 2 NgForm Reset



Asked on July 29, 2017
How to reset form created by NgForm in angular 2  ?


Replied on July 29, 2017
To reset form, NgForm has resetForm() method that is called as follows.

  resetUserForm(userForm: NgForm) {
     userForm.resetForm();;
  } 

To call the above function, create a button in UI.

<button type="button" (click)="resetUserForm(userForm)">Reset</button> 

If we want to reset form with some default values, then assign the default values with form control name of the form.

resetUserForm(userForm: NgForm) {
   userForm.resetForm({
      name: 'Mahesh',
      city: 'Noida'
   });

Find the link for NgForm 



Write Answer




©2019 concretepage.com | Privacy Policy | Contact Us