Title: Unclear error message for badly configured custom form controls · Issue #44486 · angular/angular · GitHub
Open Graph Title: Unclear error message for badly configured custom form controls · Issue #44486 · angular/angular
X Title: Unclear error message for badly configured custom form controls · Issue #44486 · angular/angular
Description: Which @angular/* package(s) are relevant/releated to the feature request? forms Description I was hitting the following error when implementing a custom form control: ERROR Error: Value accessor was not provided as an array for form cont...
Open Graph Description: Which @angular/* package(s) are relevant/releated to the feature request? forms Description I was hitting the following error when implementing a custom form control: ERROR Error: Value accessor wa...
X Description: Which @angular/* package(s) are relevant/releated to the feature request? forms Description I was hitting the following error when implementing a custom form control: ERROR Error: Value accessor wa...
Opengraph URL: https://github.com/angular/angular/issues/44486
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unclear error message for badly configured custom form controls","articleBody":"### Which @angular/* package(s) are relevant/releated to the feature request?\r\n\r\nforms\r\n\r\n### Description\r\n\r\nI was hitting the following error when implementing a custom form control:\r\n\r\n```\r\nERROR Error: Value accessor was not provided as an array for form control with unspecified name attribute\r\n at _throwError (forms.mjs:1752)\r\n at selectValueAccessor (forms.mjs:1782)\r\n at new FormControlName (forms.mjs:5743)\r\n at NodeInjectorFactory.FormControlName_Factory [as factory] (forms.mjs:5827)\r\n at getNodeInjectable (core.mjs:3556)\r\n at searchTokensOnInjector (core.mjs:3493)\r\n at getOrCreateInjectable (core.mjs:3437)\r\n at ɵɵdirectiveInject (core.mjs:14720)\r\n at ɵɵinject (core.mjs:4778)\r\n at NodeInjectorFactory.factory (core.mjs:11563)\r\n```\r\n\r\nIt was very unclear to me what this error message meant or how to fix it. My form controls all had names and formControlNames.\r\n\r\nOnly by uncommenting parts of my form could I even find the offending form control, since the error doesn’t specify what it was trying to do when the error occured.\r\n\r\nGoogling the error only brought up the [source code for the test](https://github.com/angular/angular/blob/master/packages/forms/test/directives_spec.ts#L53) regarding this error, but there’s no explanation _why_ an error is thrown there, either.\r\n\r\nThe actual error was that my form control was badly configured, i.e. it provided the NG_VALUE_ACCESSOR like this:\r\n\r\n```\r\n providers: [\r\n { provide: NG_VALUE_ACCESSOR, useExisting: MyControl},\r\n ]\r\n```\r\ninstead of this\r\n```\r\n providers: [\r\n { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MyControl), multi: true },\r\n ]\r\n```\r\n\r\nMaybe related? Maybe related: https://github.com/angular/angular/issues/3011\r\n\r\nHere’s a reproduction: https://stackblitz.com/edit/angular-ivy-e2wj4z?file=src/app/app.component.ts\r\n\r\n### Proposed solution\r\n\r\nSince I still don’t know the actual cause of the error, I can’t propose a solution to a clearer error message. It would be nice to know the class or form control *something* was trying to process when the error happens.\r\n\r\nAndrew Kushnir [proposed a solution](https://github.com/angular/angular/issues/44486#issuecomment-996307788):\r\n\r\n> I think we can improve the error message by including a note like this:\r\n> \r\n> ```\r\n> Value accessor was not provided as an array for form control with unspecified name attribute.\r\n> Please make sure that the `NG_VALUE_ACCESSOR` token is configured as a multi provider (with the `multi: true` property).\r\n> ```\r\n> \r\n> I think there might also be an opportunity to improve the logic around getting the attribute name (so that there is a real name vs \"unspecified attribute\").\r\n\r\n### Alternatives considered\r\n\r\n—","author":{"url":"https://github.com/mwaibel-go","@type":"Person","name":"mwaibel-go"},"datePublished":"2021-12-15T09:42:38Z","url":"https://github.com/angular/angular/issues/44486"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a7c0b545-6990-8923-ace9-d10c82d0321a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C388:E3C4F:1065576:14ECA3E:6B0116CE |
| html-safe-nonce | 2d42f1406ae161e59a4ba1c46d4d19cb6a2b3dd046996f017c1d49965c91ac24 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzg4OkUzQzRGOjEwNjU1NzY6MTRFQ0EzRTo2QjAxMTZDRSIsInZpc2l0b3JfaWQiOiI4MjI1Mjg5ODU2MDI1MTcxNjYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9cd8db23845a78483592b44f08dacc2ae4bd19a173dca4246ed40c0fb07c6275 |
| hovercard-subject-tag | issue:1080806612 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/44486/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a34dd5aa41f539a5a60c48bca8c70aef3be50e8131d6963619f331d21f0abb6a/angular/angular/issues/44486 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a34dd5aa41f539a5a60c48bca8c70aef3be50e8131d6963619f331d21f0abb6a/angular/angular/issues/44486 |
| og:image:alt | Which @angular/* package(s) are relevant/releated to the feature request? forms Description I was hitting the following error when implementing a custom form control: ERROR Error: Value accessor wa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mwaibel-go |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width