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

前端 未结 7 1811
逝去的感伤
逝去的感伤 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:24

    04-06-2020: Ionic 5+ and Angular 9+

    Just a single line. i.e. this.form.reset();

    Resets the FormGroup, marks all descendants are marked pristine and untouched, and the value of all descendants to null.

     form: FormGroup;
    
     constructor(private formBuilder: FormBuilder, ) { }
    
      resetTheForm(): void {
        this.form.reset();
      }
    

提交回复
热议问题