我有一个 Angular Material Radio Button Group,里面有三个单选按钮。我需要检查其中一个按钮。我以为设置单选按钮组的值会检查相应的单选按钮,但事实并非如此。这就是我所拥有的。
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>
打字稿代码,试图检查单选按钮:
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
}
...
}
谢谢
皮特
答案 0 :(得分:1)
您已经将 rbgMarkType
作为 formControl
name="MarkType"
仅用于 <mat-radio-group>
SetMarkType(){
this.rbgMarkType.patchValue('3');
}