Angular |如何在初始化后扩展 FormGroup?

Angular | How to extend a FormGroup after it has be initialized?

我正在用 Angular6 编写一个系统。系统使用表单,用 FormGroup 实现。

问题:如何在初始化后扩展表单?

示例:

ngOnInit() {
    this.form = new FormGroup({
          'field_1': new FormControl(null),
          'field_2': new FormControl(null)});

    if (a == 'some value') {
       // Extend this.form with field_2 and field_3
    }
}

加属性组

if (a == 'some value') {
   this.form['field_3'] = new FormControl()
}

有一个方法叫做 addControlhttps://angular.io/api/forms/FormGroup#addControl

this.form.addControl('field3', new FormControl(null));