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.

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 issue

Which @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:closed
  • Created 2 years ago
  • Reactions:29
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

22reactions
KurtGokhancommented, Nov 30, 2021

It can also happen when you forgot to import the component’s module. I think the error message should be improved for clarity.

14reactions
LoaderB0Tcommented, Mar 1, 2022

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 and ControlValueAccessor 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:

sharedMappings.register(tsConfigPath, ['@myapp/shared', ...]) 
//                                       ^-- added shared lib to the sharedMappings declaration 
//                                           of '@angular-architects/module-federation'

In my case, the root cause of this error was that I did not share the @angular/forms package in the webpack.config.js To fix edit your webpack.config.js files from all affected apps:

module.exports = {
...
  plugins: [
    new ModuleFederationPlugin({
      remotes: {
         ...
      },
      shared: share({
        '@angular/forms': { // <-- This was missing
          singleton: true,
          strictVersion: true,
          requiredVersion: 'auto',
          includeSecondaries: true
        },
        ...
      }),
      ...
    }),
    ...
  ]
};

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

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