取消选择单选按钮 Angular 2? [英] Deselect radio button Angular 2?
本文介绍了取消选择单选按钮 Angular 2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试取消选择 Angular 2 中的单选按钮.我尝试了以下代码,但没有帮助.
I am trying to deselect a radio button in Angular 2. I tried the following code but it doesn't help.
.html
<div [formGroup]="myForm">
<mat-radio-group matInput (click)= "resetRadio($event)" formControlName="RdoSel">
<mat-radio-button *ngFor="let RadioOpt of RadioOpts" [value]="RadioOpt .id">{{RadioOpt .value}}</mat-radio-button>
</mat-radio-group>
</div>
.ts
public RadioOpts= [
{ id: 'Market', value : 'Market'},
{ id: 'Segment', value : 'Segment'}
];
public resetRadio(event: any) {
if(myForm.get('RdoSel').value===event.target.value){
myForm.get('RdoSel').setValue('false');
}
当我 console.log(event.target.value)
它返回 <div>
标签.有人可以告诉我如何取消选择 Angular 2 中的单选按钮吗?
When I console.log(event.target.value)
it returns <div>
tags. Could someone please tell me how to deselect a radio button in Angular 2?
推荐答案
使用响应式表单,我们可以使用
Using reactive forms, we can use
yourFormName.controls['youRradioFormContolName'].reset();
这会将您的收音机重置为未选中.
this will reset you radio to unchecked.
这篇关于取消选择单选按钮 Angular 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文