Search code examples
angularangular2-forms

How to set a form as pristine?


  • 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.


Solution

  • 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.