I’m using toggles for my settings page and I’m using ionChange to do stuff every time the toggle is interacted with but every time the page opens and gets the values it toggles the settings to on and triggers ionChange.
Is there any way i can prevent this from happening unless the toggle is directly interacted with?
In settings.ts
constructor(...) {
this.settings = {
...
notificationSound: this.settingsData.getNotificationSound()
};
}
updateNotificationSound() {
this.settingsData.setAlarmRing(this.settings.notificationSound);
this.notifData.setNotificationSound();
// Cancel any existing notifications so that future notification sounds match the settings
LocalNotifications.cancelAll();
this.notifData.setNotification();
}
In settings.html
<ion-item>
<ion-label>Play sound on notification</ion-label>
<ion-toggle [(ngModel)]="settings.notificationSound" (ionChange)="updateNotificationSound()"></ion-toggle>
</ion-item>