Reputation: 1065
I've got an Angular Material Radio Button Group with three radio buttons inside. I need to check one of the buttons. I thought setting the value of the radio button group would check the corresponding radio button, but its not. here's what I've got.
HTML template
<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 code, attempting to check radio button:
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
}
...
}
Thanks
Pete
Upvotes: 0
Views: 992
Reputation: 1132
You already have your rbgMarkType
as formControl
name="MarkType"
is only there for the name of the <mat-radio-group>
SetMarkType(){
this.rbgMarkType.patchValue('3');
}
Upvotes: 1