Prerak Tiwari Prerak Tiwari - 1 month ago 5x
TypeScript Question

Check Ionic 2 Radio Button Programmatically using TypeScript

Lets say I have the following list:

<ion-list radio-group [(ngModel)]="autoManufacturers">
Auto Manufacturers

<ion-radio value="cord"></ion-radio>

<ion-radio value="duesenberg"></ion-radio>

<ion-radio value="hudson"></ion-radio>

Depending upon what value I get from the database, I want to check the item in the list. Lets say if I get value 'cord' then item 2 should displayed as selected item. How can I achieve this using TypeScript?


Since you're binding the radio group to the autoManufacturers property from your Component, the only thing you need to do is assigning to that property the value you get from the database:

// somewhere in your code
this.autoManufacturers = valueFromDataBase; // where valueFromDataBase === 'cord'

By doing that, the option with the cord value will be selected automatically.