Angular 2: Iterate over reactive form controls

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

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

9条回答
  •  日久生厌
    2020-12-02 07:50

    For what it's worth, there's another way to do this without having to use Object.keys(...) magic:

    for (const field in this.form.controls) { // 'field' is a string
    
      const control = this.form.get(field); // 'control' is a FormControl  
    
    }
    

提交回复
热议问题