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.

No value accessor for from control

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

There should be an value accessor.

What is the current behavior?

main.987e5bf….bundle.js:17 EXCEPTION: No value accessor for form control with name: 'username'

What are the steps to reproduce?

This bug occurs only if you run ng build --prod.

Use angular-cli@webpack to create a new project.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms';
import { MdCardModule } from '@angular2-material/card/card';
import { MdInputModule } from '@angular2-material/input/input';
import { MdButtonModule } from '@angular2-material/button/button';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CommonModule,
    ReactiveFormsModule,
    MdCardModule,
    MdInputModule,
    MdButtonModule,
  ],
  providers: [],
  entryComponents: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {

}
<form [formGroup]="form">
  <md-card>
    <md-card-title>{{title}}</md-card-title>
    <md-card-content>
      <md-input placeholder="Username" formControlName="username"></md-input>
      <md-input placeholder="Password" formControlName="password"></md-input>
    </md-card-content>
    <md-card-actions align="end">
      <button md-button color="primary" type="submit">LOGIN</button>
    </md-card-actions>
  </md-card>
</form>

What is the use-case or motivation for changing an existing behavior?

Build an Angular2 app with prod flag.

Which versions of Angular, Material, OS, browsers are affected?

Angular@RC.5, Angular-CLI@webpack.2, Material@alpha.7-2, OSX 10.11.5

Is there anything else we should know?

As mentioned above, this only happens with the prod flag

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
maxime1992commented, May 5, 2017

With material 2.0.0-beta.3 we now have to import every modules one by one and I forgot MdSelectModule which gave me this error. (might help someone)

10reactions
YeomansIIIcommented, Aug 14, 2016

I’m also getting this error using ngModel on an input that is not even inside of a form.

<md-input placeholder="Track ID" [(ngModel)]="data.track_id"></md-input>
<md-input placeholder="Cover URL" [(ngModel)]="data.cover_url"></md-input>

Getting the error No value accessor for form control with unspecified name within browser_adapter.js.

I have FormsModule and I just tested with ReactiveFormsModule as well after reading this thread. Still getting the same error.

EDIT: I replaced md-input with a regular input tag and the page works as expected, this is defintely an issue with angular/material2.

These work fine:

<input placeholder="Track ID" [(ngModel)]="data.track_id"/>
<input placeholder="Cover URL" [(ngModel)]="data.cover_url"/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

No value accessor for form control [duplicate] - Stack Overflow
Show activity on this post. the formControlName is not located on the value accessor element. or you're not importing the module for that...
Read more >
Improve error message "No value accessor for form control ...
When you get the error No value accessor for form control with unspecified name attribute , there are generally two things that possibly...
Read more >
Creating a custom form control in Angular - Orjan De Smet
If you'd just use these directives, you'd get the error “No value accessor for form control with name: <the name of your control>”....
Read more >
No Value Accessor Error in Angular Tests - Damir's Corner
Error: No value accessor for form control with unspecified name attribute. The call stack wasn't helpful at all. It included only Angular ...
Read more >
NG01203: You must register an `NgValueAccessor` with a ...
If you defined a custom form control, did you remember to provide a value accessor? · Did you put ngModel on an element...
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