0

Why passing the value to mat-radio-group doesn't work? Any of these two buttons is checked. But if I explicitly use value="2" in mat-radio-group everything works fine.

TS inside class

 radioValue = 2;

HTML

<mat-radio-group [value]="radioValue">
        <mat-radio-button class="mr-2" value="1">Male</mat-radio-button>
        <mat-radio-button value="2">Female</mat-radio-button>
    </mat-radio-group>
2
  • 1
    use [(ngModel)], not value (or [ngModel] if you only want "one-way" binding Commented Jan 3, 2020 at 7:42
  • the above answer is correct. Commented Jan 3, 2020 at 7:47

1 Answer 1

1

The problem is related to the data type, you're merging string and number. Change your template as follows (also use [value] with mat-radio-button):

<mat-radio-group [value]="radioValue">
    <mat-radio-button class="mr-2" [value]="1">Male</mat-radio-button>
    <mat-radio-button [value]="2">Female</mat-radio-button>
</mat-radio-group> 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.