Resetting a form in Angular 2 after submit

前端 未结 12 1970
悲哀的现实
悲哀的现实 2020-12-01 03:16

I am aware that Angular 2 currently lacks a way to easily reset a form to a pristine state. Poking around I have found a solution like the one below that resets the form f

12条回答
  •  星月不相逢
    2020-12-01 03:57

    Use NgForm's .resetForm() rather than .reset() because it is the method that is officially documented in NgForm's public api. (Ref [1])

    The .resetForm() method will reset the NgForm's FormGroup and set it's submit flag to false (See [2]).

    Tested in @angular versions 2.4.8 and 4.0.0-rc3

提交回复
热议问题