Richard Richard - 1 month ago 19
TypeScript Question

How to default a ion-toggle to on?

I am using an

in Ionic 2, that I would like to default to on. I have tried the
checked
attribute, but it still defaults to off.

<ion-toggle [(ngModel)]="ratingModel.contact" formControlName="contact" id="contact" checked="true">Contactable</ion-toggle>


How do I default a
ion-toggle
to true or on?

Thanks

Answer

In your Component code, set the ratingModel.contact property to true:

ratingModel.contact = true;