我是 Angular 2 的新手。
我有一个列表并对其进行迭代并显示为单选按钮,如下所示。 现在我想设置检查属性是否条件为真。 如何在 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>
试试这个
<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>
你可以这样使用它
<input type="radio" name="optradio" [checked]="savedVal == currentRadioVal ? true : false" >
你可以用简单的方法
<input type="radio" name="Availble" [value]="true" (change)="changeLogs()" [(ngModel)]="isLogsActive" [checked]="isLogsActive">
<input type="radio" name="Unavailable" [value]="false" (change)="changeLogs()" [(ngModel)]="isLogsActive" [checked]="!isLogsActive" >
<input type="radio" name='{{prod.configurationItem}}' value = '{{prod.additionalCost}}' [checked] = "prod.isDefault == 'Y' ? true : false">
prod 是对象项