How to set radio button checked in Angular 2

后端 未结 3 1989
心在旅途
心在旅途 2020-12-14 18:00

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

相关标签:
3条回答
  • 2020-12-14 18:14

    You can use it like this

    <input type="radio" name="optradio" [checked]="savedVal == currentRadioVal ? true : false" >  
    
    0 讨论(0)
  • 2020-12-14 18:20

    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/

    0 讨论(0)
  • 2020-12-14 18:38

    <input type="radio" name='{{prod.configurationItem}}' value = '{{prod.additionalCost}}' [checked] = "prod.isDefault == 'Y' ? true : false"> prod is object item

    0 讨论(0)
提交回复
热议问题