如何以编程方式取消选中单选按钮
How to uncheck radio button programmatically
我有下面发布的单选按钮,我想知道如何使用类型脚本以编程方式取消选中它。
我尝试了以下操作,我将 averageHeight
的值设置为 false,但这并没有取消选中单选按钮。
请让我知道如何实现
html:
<div id="idRadioButtonForAverageHeightDivision">
<input [value]="0" [(ngModel)]="iOperationPasser.averageHeight" name="radioGroupForOperations" type="radio" clrCheckbox (change)="toggleShowAverageHeight()" [(checked)]="averageHeight"/>
<label id="operation-average-height">
{{ "SITE.AREAS_OF_COVERAGE_FOR_THRESHOLD.OPERATION_AVERAGE_HEIGHT" | translate }}
<button class="btn btn-sm btn-icon" (click)="showInformation('SERVICE_DIST_4_AGRI')">
<clr-icon shape="help-info" class="is-solid"></clr-icon>
</button>
</label>
</div>
收音机输入的默认行为是取消选中。
您可以使用绑定或使用 angular 来控制它的属性,只需访问 属性 checked
并更改它。
喜欢:
<input type="radio" value="exm" #radio />
// access the input with local variable on the template
<button (click)="radio.checked=false">
uncheck
</button>
或-------------------------
<input type="radio" value="exm" [checked]="term" />
// now this is toggling the checked value, so it will check and uncheck - depend on the status
<button (click)="toggle()">
uncheck
</button>
TS FILE ----------------------
public term: boolean = false
toggle(){
this.term = !this.term
}
因为您要访问值 属性,它看起来几乎相同:
<input type="radio" [value]="value" />
TS FILE ----------------------
// any change of the value will change it in the template. Since it's not a text input - ngModel is useless .
public value: string = 'Value here'
我有下面发布的单选按钮,我想知道如何使用类型脚本以编程方式取消选中它。
我尝试了以下操作,我将 averageHeight
的值设置为 false,但这并没有取消选中单选按钮。
请让我知道如何实现
html:
<div id="idRadioButtonForAverageHeightDivision">
<input [value]="0" [(ngModel)]="iOperationPasser.averageHeight" name="radioGroupForOperations" type="radio" clrCheckbox (change)="toggleShowAverageHeight()" [(checked)]="averageHeight"/>
<label id="operation-average-height">
{{ "SITE.AREAS_OF_COVERAGE_FOR_THRESHOLD.OPERATION_AVERAGE_HEIGHT" | translate }}
<button class="btn btn-sm btn-icon" (click)="showInformation('SERVICE_DIST_4_AGRI')">
<clr-icon shape="help-info" class="is-solid"></clr-icon>
</button>
</label>
</div>
收音机输入的默认行为是取消选中。
您可以使用绑定或使用 angular 来控制它的属性,只需访问 属性 checked
并更改它。
喜欢:
<input type="radio" value="exm" #radio />
// access the input with local variable on the template
<button (click)="radio.checked=false">
uncheck
</button>
或-------------------------
<input type="radio" value="exm" [checked]="term" />
// now this is toggling the checked value, so it will check and uncheck - depend on the status
<button (click)="toggle()">
uncheck
</button>
TS FILE ----------------------
public term: boolean = false
toggle(){
this.term = !this.term
}
因为您要访问值 属性,它看起来几乎相同:
<input type="radio" [value]="value" />
TS FILE ----------------------
// any change of the value will change it in the template. Since it's not a text input - ngModel is useless .
public value: string = 'Value here'