Angular Reactive forms : how to reset form state and keep values after submit

前端 未结 7 1817
逝去的感伤
逝去的感伤 2020-12-29 18:42

In an Angular reactive form. How to reset only the state of form after successful submit?

Here is the process:

  • Create the form and
7条回答
  •  执笔经年
    2020-12-29 19:17

    Adding a another answers, if you have a disabled input in your form, use getRawValue() as a parameter of ngForm.resetForm(). See the sample:

    in HTML:

    ...

    in .TS:

    formSubmit(myForm: NgForm) {
       myForm.resetForm(myForm.form.getRawValue());
    }
    

提交回复
热议问题