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) {

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) {
      name: 'Mahesh',
      city: 'Noida'

Find the link for NgForm 

Write Answer

©2023 | Privacy Policy | Contact Us