{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/13788","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/13788/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/13788/comments","events_url":"https://api.github.com/repos/angular/angular/issues/13788/events","html_url":"https://github.com/angular/angular/issues/13788","id":198841690,"number":13788,"title":"Getting \"control.registerOnChange is not a function\" after changing form","user":{"login":"natcohen","id":7813574,"avatar_url":"https://avatars3.githubusercontent.com/u/7813574?v=4","gravatar_id":"","url":"https://api.github.com/users/natcohen","html_url":"https://github.com/natcohen","followers_url":"https://api.github.com/users/natcohen/followers","following_url":"https://api.github.com/users/natcohen/following{/other_user}","gists_url":"https://api.github.com/users/natcohen/gists{/gist_id}","starred_url":"https://api.github.com/users/natcohen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natcohen/subscriptions","organizations_url":"https://api.github.com/users/natcohen/orgs","repos_url":"https://api.github.com/users/natcohen/repos","events_url":"https://api.github.com/users/natcohen/events{/privacy}","received_events_url":"https://api.github.com/users/natcohen/received_events","type":"User","site_admin":false},"labels":[{"id":393879365,"url":"https://api.github.com/repos/angular/angular/labels/comp:%20forms","name":"comp: forms","color":"c5def5","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2017-01-04T23:55:12Z","updated_at":"2017-09-24T05:29:58Z","closed_at":null,"author_association":"NONE","body":"**I'm submitting a ...**  (check one with \"x\")\r\n```\r\n[ x ] bug report => search github for a similar issue or PR before submitting\r\n[   ] feature request\r\n[   ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n```\r\n\r\n**Current behavior**\r\n<!-- Describe how the bug manifests. -->\r\nAfter 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) {`.\r\n\r\nWhen 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`.\r\n\r\nThe 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!\r\n\r\n\r\n**Expected behavior**\r\n<!-- Describe what the behavior would be without the bug. -->\r\nIt should not throw any error...\r\n\r\n\r\n**Minimal reproduction of the problem with instructions**\r\n<!--\r\nIf the current behavior is a bug or you can illustrate your feature request better with an example, \r\nplease provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via\r\nhttps://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).\r\n-->\r\nI couldn't make a minimal demo but would definitely share the functions I use to create the form if needed.\r\n\r\n**What is the motivation / use case for changing the behavior?**\r\n<!-- Describe the motivation or the concrete use case -->\r\n\r\n**Please tell us about your environment:**\r\n<!-- Operating system, IDE, package manager, HTTP server, ... -->\r\nNodeJS 7.4.0 running on Windows 10\r\n\r\n* **Angular version:** 2.4.7\r\n\r\n* **Browser:** Chrome 55 64bit\r\n\r\n* **Language:** Typescript"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/331688302","html_url":"https://github.com/angular/angular/issues/13788#issuecomment-331688302","issue_url":"https://api.github.com/repos/angular/angular/issues/13788","id":331688302,"user":{"login":"manisabri","id":1507502,"avatar_url":"https://avatars1.githubusercontent.com/u/1507502?v=4","gravatar_id":"","url":"https://api.github.com/users/manisabri","html_url":"https://github.com/manisabri","followers_url":"https://api.github.com/users/manisabri/followers","following_url":"https://api.github.com/users/manisabri/following{/other_user}","gists_url":"https://api.github.com/users/manisabri/gists{/gist_id}","starred_url":"https://api.github.com/users/manisabri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manisabri/subscriptions","organizations_url":"https://api.github.com/users/manisabri/orgs","repos_url":"https://api.github.com/users/manisabri/repos","events_url":"https://api.github.com/users/manisabri/events{/privacy}","received_events_url":"https://api.github.com/users/manisabri/received_events","type":"User","site_admin":false},"created_at":"2017-09-24T05:29:58Z","updated_at":"2017-09-24T05:29:58Z","author_association":"NONE","body":"I'm having the same problem with dynamically adding custom controls in a formArray on the fly. The workarounds are horrible. \r\nI can dismantle the custom control and just pass in the formGroup instance and go from there but it makes the code much harder to maintain and doesn't count as encapsulation.  "}}
{"actor":{"display_login":"manisabri"}}