Mohan Gopi
Mohan Gopi

Reputation: 7724

how to handle click function on ion-toggle

here is my .html file

<ion-item no-lines (click)="update()" >
        <ion-label> Notification</ion-label>
        <ion-toggle [(ngModel)]="notify" ></ion-toggle>
    </ion-item>

the above code works when i click on the Notification text but when i click on the ion-toggle i am not able to invoke the function what should i do to invoke the function.

here is my .ts file

update(){
 console.log("invoking notification");
}

Upvotes: 12

Views: 15039

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657416

If you use ngModel it's best to use ngModelChange

<ion-toggle [(ngModel)]="notify" (ngModelChange)="update($event)" ></ion-toggle>

otherwise you can use

<ion-toggle (ionChange)="update($event)"></ion-toggle>

See also https://ionicframework.com/docs/api/components/toggle/Toggle/

Upvotes: 29

Related Questions