Fábio Heitor
Fábio Heitor

Reputation: 105

Change ion-toggle visual toggling with a variable value by true or false

I thought I had this done but no.

Somehow I can't make to change the toggling of my ion-toggle visual value, with a variable number.

I start my app with my variable at a false state, but my ion-toggle starts actively.

<ion-toggle
  checked="loyaltyCardActiveState"
  [ngModel]="loyaltyCardActiveState"
  (click)="activeLoyaltyCard()"
></ion-toggle>

loyaltyCardActiveState is false at the start, but the toggle is active. What I am doing wrong?

Upvotes: 0

Views: 998

Answers (3)

Daniel Kimaiga
Daniel Kimaiga

Reputation: 1

<ion-toggle
  [checked]="loyaltyCardActiveState"
  (ionChange)="activeLoyaltyCard()">
</ion-toggle>

Upvotes: 0

Hamza Meghlaoui
Hamza Meghlaoui

Reputation: 146

use ionChange event:

`<ion-toggle
  checked="loyaltyCardActiveState"
  [ngModel]="loyaltyCardActiveState"
  (ionChange)="activeLoyaltyCard()"
></ion-toggle>`

Upvotes: 0

Arunkumar Ramasamy
Arunkumar Ramasamy

Reputation: 781

You are using one way binding to your [ngModel]

Please change it to [(ngModel)] It'll change toggling visual value.

Let me know if it works

Upvotes: 1

Related Questions