[英]set Angular Material Radio Button checked within a Radio Button Group
我有一個 Angular 材質單選按鈕組,里面有三個單選按鈕。 我需要檢查其中一個按鈕。 我認為設置單選按鈕組的值會檢查相應的單選按鈕,但事實並非如此。 這就是我所擁有的。
HTML 模板
<mat-radio-group [formControl]="rbgMarkType" name="MarkType">
<mat-radio-button value=1>Marked In Field</mat-radio-button>
<mat-radio-button value=2>No Conflict</mat-radio-button>
<mat-radio-button value=3>Cancel</mat-radio-button>
</mat-radio-group>
typescript 代碼,嘗試檢查單選按鈕:
export class MtMarkFormComponent implements OnInit {
...
rbgMarkType:FormControl = new FormControl();
...
ngAfterViewInit() {
this.SetMarkType();
}
SetMarkType(){
this.rbgMarkType.patchValue({MarkType:3});//sets value but doesn't check radio button
}
...
}
謝謝
皮特
您已經將rbgMarkType
作為formControl
name="MarkType"
僅用於<mat-radio-group>
的名稱
SetMarkType(){
this.rbgMarkType.patchValue('3');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.