I am experiencing a successful operation with my mat-radio-button component.
However, my goal is to programmatically select the correct button once I receive the necessary parameters.
Below is the HTML code snippet:
<form [formGroup]="seasonFrmGroup">
<mat-radio-group aria-labelledby="radio-group-label2" class="radio-group" [(ngModel)]="selectedSeasonType"
formControlName="btnSeason" fxLayoutAlign="center">
<mat-radio-button class="radio-button" selectedSeasonTypevalue="s" (change)="radioChoiceSeason('s')">
{{'Season' | translate }}
</mat-radio-button>
<mat-radio-button class="radio-button" selectedSeasonTypevalue="p" (change)="radioChoiceSeason('p')">
{{'Playoffs' | translate }}
</mat-radio-button>
</mat-radio-group>
</form>
In my .ts file, I aim to automatically select the radio-button with the 's' parameter:
ngOnInit() {
this.seasonFrmGroup = new FormGroup({
'btnSeason': new FormControl()
});
this.seasonFrmGroup.get("btnSeason").patchValue("s");
}
Unfortunately, I'm encountering the following errors:
ERROR Error: formGroup expects a FormGroup instance. Please pass one in. ERROR TypeError: Cannot read properties of undefined (reading 'get')
It has been a while since I last updated this code, and I am struggling to identify the missing piece to resolve these issues. Any guidance on how to correctly select my radio-button during initialization would be greatly appreciated. Thank you.