Improve error message "No value accessor for form control with unspecified name attribute" to suggest what to do to fix the issue
See original GitHub issueWhich @angular/* package(s) are relevant/releated to the feature request?
forms
Description
When you get the error No value accessor for form control with unspecified name attribute
, there are generally two things that possibly has gone wrong:
You are using ngModel
with a third party control that doesn’t register a NG_VALUE_ACCESSOR
. In this case you need to use ngDefaultControl
on the element.
Alternatively you have forgotten to register a NG_VALUE_ACCESSOR
for your custom form input:
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MyInputField),
multi: true
}
]
Proposed solution
It would be very nice if the error message Angular generated would actually suggest on of those things as being the actually problem, and thus what you should probably do to fix it, in the error message.
Alternatives considered
I mean, Angular could just leave it as is, and people can keep using Google I guess, though that is a suboptimal solution in my opinion.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:29
- Comments:11 (3 by maintainers)
Top Results From Across the Web
No value accessor for form control with unspecified name ...
The error was caused, apparently by the project trying to render the page, apparently at the moment of evaluating the variable, the project...
Read more >Angular 7 - No value accessor for form control with ... - YouTube
HTML : Angular 7 - No value accessor for form control with unspecified name attribute [ Beautify Your Computer ...
Read more >When to Use Angular ControlValueAccessor and What's the ...
But if we do this, there will be an error, — Error: No value accessor for form control with the unspecified name attribute....
Read more >no value accessor for form control with name - You.com
I fixed this error by adding the name="fieldName" ngDefaultControl attributes to the element that carries the [(ngModel)] attribute. Open side panel. No value...
Read more >How to use ControlValueAccessor to enhance date input with ...
Our directive will be used by Angular to set-up synchronisation with FormControl . implement ed the ControlValueAccessor interface.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It can also happen when you forgot to import the component’s module. I think the error message should be improved for clarity.
I came across this error under fairly specific circumstances while migrating an angular project to Nx with Module Federation. Just in case anyone comes across this issue with a similar situation.
I have a shared library that declares a custom control with the
NG_VALUE_ACCESSOR
andControlValueAccessor
mechanics that is used in different Module-Federation-enabled apps in my workspace.Worked fine at first but when I declared in the webpack.config.js that the shared library should actually be shared and not be included twice the controls broke with the mentioned very unhelpful error message:
In my case, the root cause of this error was that I did not share the
@angular/forms
package in thewebpack.config.js
To fix edit yourwebpack.config.js
files from all affected apps:I know this is very specific, but still, the error message did not lead me anywhere useful 😃 So would be cool if the message would give a better hint at what is broken.