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.

'mat-radio-button' throwing no value accessor for form control

See original GitHub issue

I just tried to bind formcontrolName with mat-radio-button

HTML

<div [formGroup]="sampleFormGroup"> 
  <mat-radio-group class="radio-btn-wrapper">
     <mat-radio-button id="sample" (click)="valuechange('sampleVal')" name="sample" value="sampleVal" [checked]="sampleVal" formControlName="sampleType"></mat-radio-button>                                            
  </mat-radio-group>
</div>  

TypeScript

sampleType = new FormControl('', []);

 ngOnInit() {


        this.sampleFormGroup = new FormGroup({
            sampleType: this.sampleType          
        })
    }

but I’m getting console error as

No value accessor for form control with name: 'sample'

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
tfalvocommented, Nov 24, 2017

Try to set formControlName="sampleType" on <mat-radio-group> and not on <mat-radio-button>. It should works.

9reactions
inthegaragecommented, Mar 19, 2018

@josephperrott I would like this ticket reopened as with the example code taken from the material site a spec fails with the same error:

<mat-radio-group class="example-radio-group" [(ngModel)]="favoriteSeason">
  <mat-radio-button class="example-radio-button" *ngFor="let season of seasons" [value]="season">
    {{season}}
  </mat-radio-button>
</mat-radio-group>
<div class="example-selected-value">Your favorite season is: {{favoriteSeason}}</div>

Taken from this link: https://material.angular.io/components/radio/examples

You have to stop using the ngModel way of doing things to get this to work and that doesn’t seem right to me.

The error again is: Error: No value accessor for form control with unspecified name attribute

Either the documentation isn’t quite right or mat-radio-group should support the ngModel. I can create a new ticket if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<mat-radio-button> : No value accessor - Stack Overflow
Try to set formControlName="SearchType" on <mat-radio-group> and not on <mat-radio-button> .
Read more >
Material radio-button, getting "ERROR Error: No value ... - Reddit
I am trying to use material radio buttons in a reactive form but get the error message ERROR Error: No value accessor for...
Read more >
[Solved] ERROR Error: No value accessor for form control with ...
I used mat-radio-button, mat-checkbox in my template page. But I missed to import the radio module and FormsModule in my app module. Solutions:....
Read more >
Angular 7 - No Value Accessor For Form Control With Name
I fixed this error by adding the namefieldName ngDefaultControl attributes to the element that carries the [ngModel] attribute. I had the same problem....
Read more >
No value accessor for form control with name: ''-angular.js
You can't apply a formControlName directive to an strong tag. It must be applied on a form field tag ( select , input...
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