1

I'm trying to set a value programatically of a md-radio-button inside of a md-radio-group. Here is my code simplified :

<md-radio-group [(ngModel)]="radioGroupValue">
    <div *ngFor="let answer of answers; let i = index">
       <md-checkbox *ngIf="isMultiple" [(ngModel)]="answer.isCorrect" [value]="i" ngDefaultControl></md-checkbox>
       <md-radio-button *ngIf="!isMultiple" [(ngModel)]="answer.isCorrect" [value]="i" ngDefaultControl></md-radio-button>
       {{ answer.text }}
    </div>
</md-radio-group>

When I change isMultiple from true to false, I update radioGroupValue too. The first time, there is no md-radio-button checked, and if I change isMultiple to true again and false, the right radiobutton is checked. How can I handle that ?

4
  • Looks like you spelt *ngIf as *nfIf! Commented Jun 20, 2017 at 9:23
  • Yes my bad, I didn't put all my code to be cleaner, so I made a little mistake here ^^, but there is no syntax issue in my component (at least I didn't have an error on console) Commented Jun 20, 2017 at 9:26
  • Is it allowed to have md-checkbox inside md-radio-group? Commented Jun 20, 2017 at 12:39
  • Why not ? You can place what you want anywhere, it's just doing nothing on the checkbox Commented Jun 21, 2017 at 7:27

1 Answer 1

2

To check a md-radio-group we need to use [checked]="boolean" on the html template

<md-input-container [checked]="answer.isCorrect"> {{ answer.text }}</md-radio-button>
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.