簡體   English   中英

設置 Angular 在單選按鈕組中選中的材質單選按鈕

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM