Angular form reset



In this video we will discuss, why and how to rest a form in angular.

Sometimes we must reset the form, before we can redirect the user to another route. Let me explain this with an example.

1. We have a form to create a new employee

2. After we fill the form and when we click the “Save” button, the employee data must be saved and the user should be redirected to the “LIST” route.

3. But canDeactivate guard is added on the “CREATE” route

4. This means if the form is dirty, the canDecativate guard will prevent us from leaving the “CREATE” route

5. So there is a need to to RESET the form, which will reset all the form control values to their intial state and also resets the form flags like dirty, pristine, valid, touched etc.

6. Once the form is REST, the form is no longer dirty, so the canDeactivate guard will not prevent use from leaving the CREATE route

Angular form reset

1. Clears all the form controls

2. Optionally the form controls can be initialised with default…

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *