如何设置单选按钮根据Angular中的条件选中2
How to set radio button checked based on condition in Angular 2
如何为单选按钮设置 checked
和 click
事件。
场景:
如果是服务组应该首先选中并禁用单选按钮2
按钮和块。
如果它是访问组,则两个收音机都应该正常运行,并在单击每个收音机时正确显示div。
我试过类似的方法。
<label for="{{radio1.id}}" class="radio" (click)="radioSelected(radio1.label)">
<input type="radio" id="{{radio1.id}}" name="optionsRadio41" value="{{radio1.value}}" required="" [disabled]="requestGroupName == 'SERVICE_GROUP'" [checked]="GroupName ==='ACCESS_GROUP'">
<i class="skin"></i>
<span>Within this solution</span>
</label>
<label for="{{radio2.id}}" class="radio" (click)="radioSelected(radio2.label)">
<input type="radio" id="{{radio2.id}}" [checked]="GroupName ==='SERVICE_GROUP'" name="optionsRadio41" value="{{radio2.value}}" required="">
<i class="skin"></i>
<span>Copy to a different solution</span>
</label>
<div *ngIf="radioSelectedLabel=='Within this solution'">first block </div>
<div *ngIf="radioSelectedLabel=='Within this solution'">second block</div>
我怎样才能同时满足这两个条件?
这是工作示例,请看一下。
https://stackblitz.com/edit/angular-basic-tutorial-zaaf4q
如果你想切换属性,你需要做 [attr.checked]
而不是 [checked]
,但在你的情况下它不起作用,因为你需要删除或添加属性。
我已经创建了指令,该指令采用 {attributeName: boolean,attributeName2: boolean, ... }
等属性的对象,并将根据属性值添加或删除属性。
如何为单选按钮设置 checked
和 click
事件。
场景:
如果是服务组应该首先选中并禁用单选按钮2 按钮和块。
如果它是访问组,则两个收音机都应该正常运行,并在单击每个收音机时正确显示div。
我试过类似的方法。
<label for="{{radio1.id}}" class="radio" (click)="radioSelected(radio1.label)">
<input type="radio" id="{{radio1.id}}" name="optionsRadio41" value="{{radio1.value}}" required="" [disabled]="requestGroupName == 'SERVICE_GROUP'" [checked]="GroupName ==='ACCESS_GROUP'">
<i class="skin"></i>
<span>Within this solution</span>
</label>
<label for="{{radio2.id}}" class="radio" (click)="radioSelected(radio2.label)">
<input type="radio" id="{{radio2.id}}" [checked]="GroupName ==='SERVICE_GROUP'" name="optionsRadio41" value="{{radio2.value}}" required="">
<i class="skin"></i>
<span>Copy to a different solution</span>
</label>
<div *ngIf="radioSelectedLabel=='Within this solution'">first block </div>
<div *ngIf="radioSelectedLabel=='Within this solution'">second block</div>
我怎样才能同时满足这两个条件?
这是工作示例,请看一下。
https://stackblitz.com/edit/angular-basic-tutorial-zaaf4q
如果你想切换属性,你需要做 [attr.checked]
而不是 [checked]
,但在你的情况下它不起作用,因为你需要删除或添加属性。
我已经创建了指令,该指令采用 {attributeName: boolean,attributeName2: boolean, ... }
等属性的对象,并将根据属性值添加或删除属性。