How do you submit a reactive form and reset it afterwards?

Angular forms · Freshers

Model answer

Bind (ngSubmit)="save()" on the form element and [formGroup]="form". In save(), check form.valid, read form.getRawValue() or form.value, and send it to a service. If it is invalid, call form.markAllAsTouched() so all errors become visible.

After a successful save, call form.reset() to clear it (pass default values if needed). Disable the submit button while the request is running to stop double submissions, and show a clear success or error message.

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions