fraxool
fraxool

Reputation: 3229

Programmatically checking a ion-radio from TypeScript

I have a pretty simple question but I can't find any answer. I have this code :

<ion-list radio-group [(ngModel)]="profile_activities" name="activities">
    <ion-item>
        <ion-label>Option 1</ion-label>
        <ion-radio  (ionSelect)='selectedActivity($event);' value="0"></ion-radio>
    </ion-item>

    <ion-item>
        <ion-label>Option 2</ion-label>
        <ion-radio (ionSelect)='selectedActivity($event);' value="1"></ion-radio>
    </ion-item>

    <ion-item>
        <ion-label>Option 3</ion-label>
        <ion-radio (ionSelect)='selectedActivity($event);' value="2"></ion-radio>
    </ion-item>
</ion-list>

... and I would just like to pre-check a value from typescript based on an info I get from my database. How can I check a ion-radio from Typescript?

Thanks!

Upvotes: 5

Views: 2768

Answers (2)

Mahendra
Mahendra

Reputation: 457

in my case ionic 6, angular 12

if worked like this

<ion-list radio-group value="{{profile_activities}}" name="activities">
......

Upvotes: 0

fraxool
fraxool

Reputation: 3229

Ok, managed to find the answer by myself. In TypeScript, I just need to enter the default value of the radio to be checked like that :

this.profile_activities = "1";

... for example, in the ionViewWillEnter() function and the radio with value="1" is checked !

Upvotes: 3

Related Questions