我有下面發布的單選按鈕,我想知道如何使用型別腳本以編程方式取消選中它。我嘗試了以下操作,我將 的值設定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>
uj5u.com熱心網友回復:
無線電輸入的默認行為是取消選中。
您可以使用 bind 或 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
}
當您要訪問 value 屬性時,它看起來幾乎相同:
<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'
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347496.html
