如何设置Angular 2中选中的单选按钮 [英] How to set radio button checked in Angular 2
本文介绍了如何设置Angular 2中选中的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Angular 2的新手.
I am new to Angular 2.
我有一个列表并对其进行迭代,并显示为单选按钮,如下所示.现在,如果条件为TRUE,我想设置检查属性.如何在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>
推荐答案
尝试一下
<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>
在线演示: https://embed.plnkr.co/jSht4Do3DzpoVQG2SAwl/
这篇关于如何设置Angular 2中选中的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文