V
V
vrazbros2019-07-22 13:47:17
Angular
vrazbros, 2019-07-22 13:47:17

How to mark radio button as default in angular 8?

There are two radio buttons on the page, you need to mark one of them by default, tried various checked and checked="true" attributes, but unfortunately nothing works. I found options on Google, but they seem to be suitable only for angularJS or angular 2 ... and I use angular 8.
Here is the code itself in test.component.html:

<div class="form-check" >
        <mat-radio-button type="radio" class="form-check-input" id="materialUnchecked" name="filterType" value="0" [(ngModel)]="filterType" [checked]="true">By client</mat-radio-button>

        <mat-radio-button type="radio" class="form-check-input" id="materialChecked" name="filterType" value="1" [(ngModel)]="filterType">By student</mat-radio-button>
        <br><br>
    </div>

test.component.ts:
protected filterType;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-07-22
@vrazbros

Wrap the buttons in mat-radio-group, which you add [(ngModel)]="filterType"(and remove from the buttons themselves). Well, let it initially filterTypebe equal to "0"or "1", depending on which of the buttons you should have active.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question