如何在Angular 2中设置单选按钮

时间:2017-02-06 02:07:06

标签: angular

我是Angular 2的新手。

我有一个列表并重复它并显示为单选按钮,如下所示。现在我想在条件为TRUE时设置check属性。如何在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>

3 个答案:

答案 0 :(得分:33)

试试这个

<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/

答案 1 :(得分:3)

您可以像这样使用它

<input type="radio" name="optradio" [checked]="savedVal == currentRadioVal ? true : false" >  

答案 2 :(得分:1)

产品是对象项

相关问题