I have a mat-radio-button and it works perfectly.
But what I want is : When I receive the parameters, I want to select the right button. So I need to access my button and select it programmatically.
Here's the HTML
<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>
And in my .ts file, I want to select my radio-button (Here I supposed that my parameter received is the S
ngOnInit() {
this.seasonFrmGroup = new FormGroup({
'btnSeason': new FormControl()
});
this.seasonFrmGroup.get("btnSeason").patchValue("s");
}
But I have these errors:
ERROR Error: formGroup expects a FormGroup instance. Please pass one in. ERROR TypeError: Cannot read properties of undefined (reading 'get')
It's been a long time that I didn't modify the code, and I don't see what I missing to make it works. Maybe I'm close of the answer, maybe I'm totally out of it, but I search and I didn't found a solution telling how to select my radio-button on the init.
Thanks
