How to set a form as pristine?

Daniel Birowsky Popeski picture Daniel Birowsky Popeski · May 13, 2016 · Viewed 31.7k times · Source
  • The form that represents entity state is being edited (turns dirty)
  • The form is being submitted and entity state is now aligned with the form state which means that the form should now be set as pristine.

How do we do that? There was $setPristine() in ng1. Btw, I'm talking about ControlGroup type of form.

Answer

Christophe Vidal picture Christophe Vidal · Sep 19, 2016

There is the markAsPristine method (it seems undocumented for now, but can be found here: https://github.com/angular/angular/blob/53f0c2206df6a5f8ee03d611a7563ca1a78cc82d/tools/public_api_guard/forms/index.d.ts#L42).

Basically, this.form.markAsPristine() does what you expect.