Lets say I have the following list:
<ion-list radio-group [(ngModel)]="autoManufacturers">
<ion-list-header>
Auto Manufacturers
</ion-list-header>
<ion-item>
<ion-label>Cord</ion-label>
<ion-radio value="cord"></ion-radio>
</ion-item>
<ion-item>
<ion-label>Duesenberg</ion-label>
<ion-radio value="duesenberg"></ion-radio>
</ion-item>
<ion-item>
<ion-label>Hudson</ion-label>
<ion-radio value="hudson"></ion-radio>
</ion-item>
</ion-list>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With