gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:54:57 25 4
gpt4 key购买 nike

我是 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>

在线演示:https://embed.plnkr.co/jSht4Do3DzpoVQG2SAwl/

关于angular - 如何设置在 Angular 2 中选中的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42059444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com