Reputation: 427
I am currently using angular 4.0. I have two radio buttons, how to set some radio button by default.
<div class="row" style="margin-top: 5px;margin-left: 5px;">
<input type="radio" value="timeShift" (click)="selectOption($event)" ngModel="mValue" > TIMESFTO & TIMESFT1
</div>
<div class="row" style="margin-top: 5px;margin-left: 5px;">
<input type="radio" value="rsh" (click)="selectOption($event)" ngModel="mValue" checked="checked"> RSH1
</div>
Upvotes: 1
Views: 5005
Reputation: 6311
you can use [checked]
to make radio button checked
<div class="row" style="margin-top: 5px;margin-left: 5px;">
<input type="radio" [value]="'timeShift'" > TIMESFTO & TIMESFT1
</div>
<div class="row" style="margin-top: 5px;margin-left: 5px;">
<input type="radio" [value]="'rsh'" [checked]="true"> RSH1
</div>
Upvotes: 0
Reputation: 2763
You can use value attribute to checked by default.
<div class="row" style="margin-top: 5px;margin-left: 5px;">
<input type="radio" [value]="true"
(click)="selectOption($event)" ngModel="mValue" > TIMESFTO &
TIMESFT1
</div>
<div class="row" style="margin-top: 5px;margin-left: 5px;">
<input type="radio" [value]="true" (click)="selectOption($event)"
ngModel="mValue" checked="checked"> RSH1
</div>
Or You need to set value of variable timeShift/rsh in component with boolean true.
Upvotes: 1