Search code examples
angulartypescriptionic2

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!


Solution

  • 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 !