Angular 2: Iterate over reactive form controls

前端 未结 9 767
遥遥无期
遥遥无期 2020-12-02 07:23

I would like to markAsDirty all the controls inside of a FormGroup.

9条回答
  •  旧时难觅i
    2020-12-02 07:56

    This is what working for me

    private markFormGroupTouched(formGroup: FormGroup) {
      Object.keys(formGroup.controls).forEach((key) => {
        const control = formGroup.controls[key];
        control.markAsDirty();
        if ((control instanceof FormGroup)) {
          this.markFormGroupTouched(control);
        }
      });
    }
    

提交回复
热议问题