question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "control.registerOnChange is not a function" after changing form

See original GitHub issue

I’m submitting a … (check one with “x”)

[ x ] bug report => search github for a similar issue or PR before submitting
[   ] feature request
[   ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

After patching a form of type FormArray (form.patchValue(myArray);) with FormGroup items, [formGroup]='form' in my html throws control.registerOnChange is not a function. I patch it when I initialize my app and everything works fine but when I change the form with another FormArray (I tried with the same array), I’m getting this error. After further investigation (and hours trying to understand what was going on), it seems that the error comes from line 1634 of forms.umd.js when it does control.registerOnChange(function (newValue, emitModelEvent) {.

When it works, control (of control.registerOnChange) is of form FormControl while when it fails, it is of form FormGroup. The problem is that my FormArray is somewhat deep and the first time I patch it, it goes at the leaf of the branches to reach FormControl while the second time it goes to the first branch which in my case is a FormGroup.

The problem is that I don’t know why it doesn’t go to the leaf the second time. I use the same functions and methodology to patch the values and the FormArray looks exactly the same in both cases!

Expected behavior

It should not throw any error…

Minimal reproduction of the problem with instructions

I couldn’t make a minimal demo but would definitely share the functions I use to create the form if needed.

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

NodeJS 7.4.0 running on Windows 10

  • Angular version: 2.4.7

  • Browser: Chrome 55 64bit

  • Language: Typescript

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:38 (7 by maintainers)

github_iconTop GitHub Comments

25reactions
natcohencommented, Oct 27, 2017

This should have been fixed a long time ago 😦

I understand angular’s team has a lot to do but this is almost a one year old bug and I’m still having lots of troubles with it…

19reactions
natcohencommented, Nov 21, 2019

Almost 3 years and not a word from the Angular team!

It is a shame that the Angular community spends time to find bugs and work on solutions but the team doesn’t pay attention to that! What should I do to get it fixed in the next release?

I am currently working on a new project and have moved to React… I love Angular but if we can’t get the support we need after 3 years, it makes it unusable!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What causes the "control.registerOnChange is not a ...
In my case I got the error when I used formControlName in the template when actual form model was a FormGroup instance. Changing...
Read more >
ERROR Error: control.registerOnChange is not a function
I am using Control Value Accessor to have a reusable form. I am going to be displaying a list of these forms and...
Read more >
control.registeronchange is not a function
If you're using form group along from array then you may get you may get this error 'control register on change is not...
Read more >
What causes the "control.registerOnChange is not ... - YouTube
forms : What causes the " control. registerOnChange is not a function " errorThanks for taking the time to learn more.
Read more >
Angular – What causes the “control.registerOnChange is ...
Everything works fine except when I try to change the form (which is a FormArray ) in the javascript part. I get the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found