What causes the “control.registerOnChange is not a function” error

后端 未结 10 2069
一向
一向 2020-12-01 20:39

I have a form using the reactive form approach. The form is created as follow in my pug:

form([formGroup]=\'form\', novalidate=\'\', (ngSubmit)=\'postSurvey(         


        
10条回答
  •  甜味超标
    2020-12-01 20:59

    I came across looking for a solution to the similar issue and then found a solution myself. My issue was the following. I had a form like this

    form: FormGroup = new FormGroup({
      status: new FormArray([])
    });
    

    Initially it was represented by the list of checkboxes for each status on the template. And then I created a custom component to represent status selector and used it in template like so

    
    

    The problem is that formControlName must point to FormControl instance, but actually it was pointing to a FormArray instance. So, changing to status: new FormControl([]) fixed this issue for me.

提交回复
热议问题