Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 check radio button by default

Tags:

angular

I am trying to check my radio button with zero value by default. I am trying to use the [checked]='true' attribute. But that does not work.

<input type="radio" name="unitTrusts-pnl" id="unitTrusts-pnl0" class="with-gap" [value]="0" [(ngModel)]="unitTrustsPnl"  [checked]='true'>
<input type="radio" name="unitTrusts-pnl" id="unitTrusts-pnl0" class="with-gap" [value]="1" [(ngModel)]="unitTrustsPnl">

DEMO

https://stackblitz.com/edit/angular-jj9gib

like image 552
Kiran Dash Avatar asked May 25 '18 07:05

Kiran Dash


1 Answers

Try adding this in addition to the [checked] you already have:

[attr.checked]="true"
like image 65
rrd Avatar answered Oct 18 '22 18:10

rrd