components icon indicating copy to clipboard operation
components copied to clipboard

RadioButton checked does not work with value is a number

Open DevilHeS opened this issue 8 years ago • 6 comments

This is my test code:

** <mat-radio-button class="example-radio-button" [checked]="true" [value]="12"> Radio Test ** d 7z zl isl x8_i 1oijt ** <mat-radio-button class="example-radio-button" [checked]="true" [value]="ThisIsAString"> Radio Test ** hz 1e okf1ep9wl 6o2 d o

version info: "@angular/core": "5.2.7", "@angular/forms": "5.2.7", "@angular/material": "^5.2.4", "@angular/cdk": "^5.2.4", "typescript": "2.6.2"

Please tell me what went wrong

DevilHeS avatar Mar 13 '18 15:03 DevilHeS

This is due to the radios having the same name property value. According to the docs:

All radio-buttons with the same name comprise a set from which only one may be selected at a time.

If you want both radios to be selected at the same time, add a name property to both radio elements with a different value.

Demo

jtwotimes avatar Mar 13 '18 16:03 jtwotimes

I think it's two differents code, not two buttons on the same page with the same name.

WizardPC avatar Mar 14 '18 08:03 WizardPC

OK , Thanks

DevilHeS avatar Mar 14 '18 11:03 DevilHeS

@DevilHeS I was seeing the same thing where I had a let list of radio buttons and only one was checked, but it was because of the names being the same 😄

SSTPIERRE2 avatar May 30 '19 14:05 SSTPIERRE2

<mat-radio-group [(ngModel)]="selectzhan" (change)="onSelectionChange($event)"> 8 {{'rainFall.station' | translate}} <mat-radio-button [checked]="true" value="16">16 {{'rainFall.station' | translate}} why don't

tienanhcntt2 avatar Jun 05 '19 09:06 tienanhcntt2

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.