I am new to Angular 2.
I have a list and iterate it and display as radio buttons as shown below. Now I want to set the check property if condition is TRUE. How to do that in Angular 2?
<table *ngIf="optionList"> <tr *ngFor="let op of optionList; let i = index"> <td> <input type="radio" name="optradio" *ngIf=" (CONDITION HERE) ? 'checked' : 'non' "> <label>{{op.option_text}} </label> <td> </tr> </table>
try this
<table *ngIf="optionList"> <tr *ngFor="let op of optionList; let i = index"> <td> <input type="radio" name="optradio" [checked]=" (CONDITION HERE)"> <label>{{op.option_text}} </label> <td> </tr> </table>
Online demo: https://embed.plnkr.co/jSht4Do3DzpoVQG2SAwl/
You can use it like this
<input type="radio" name="optradio" [checked]="savedVal == currentRadioVal ? true : false" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With