How to append new FormGroup or FormControl to form

前端 未结 4 1145
灰色年华
灰色年华 2021-01-31 15:28

I have the following form in Angular created with FormBuilder:

constructor(private fb: FormBuilder) {
    this.myForm = fb.group({
             


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 16:12

    I had the same issue, but since I already have a empty FormGroup {} inside the main FormGroup I was able to append FormControls like this:

    (this.myForm.get("form_group_name") as FormGroup).addControl("item1", new FormControl("default val"));
    

提交回复
热议问题