# Toggle triggers ionChange when opening page

**URL:** <https://forum.ionicframework.com/t/toggle-triggers-ionchange-when-opening-page/87400>\
**Category:** ionic-v3\
**Created:** [April 21, 2017, 10:41pm UTC](https://forum.ionicframework.com/t/toggle-triggers-ionchange-when-opening-page/87400 "2017-04-21T22:41:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake\_b](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@jake\_b](https://forum.ionicframework.com/u/jake_b)\
**Post date:** [April 21, 2017, 10:41pm UTC](https://forum.ionicframework.com/t/toggle-triggers-ionchange-when-opening-page/87400/1 "2017-04-21T22:41:50Z")

</div>

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

```auto
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

```auto

    <ion-item>
      <ion-label>Play sound on notification</ion-label>
      <ion-toggle [(ngModel)]="settings.notificationSound" (ionChange)="updateNotificationSound()"></ion-toggle>
    </ion-item>

```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [April 21, 2017, 10:43pm UTC](https://forum.ionicframework.com/t/toggle-triggers-ionchange-when-opening-page/87400/2 "2017-04-21T22:43:25Z")

</div>

Perhaps you can use some of the techniques described in [this thread](https://forum.ionicframework.com/t/toggle-change-event/46000).

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [April 21, 2017, 10:55pm UTC](https://forum.ionicframework.com/t/toggle-triggers-ionchange-when-opening-page/87400/3 "2017-04-21T22:55:32Z")

</div>

Most of my forms get initialized asynchronously, so I assign a boolean like `this.checkboxFormInitialized` to be a gatekeeper at the start of ionChange – basically the event doesn’t proceed until after the form is fully defined, so the first change is the result of user interaction, and the boolean doesn’t become true until all Observables have emitted values and the form is fully set up. The technique looks very similar to what people are doing in the thread @rapropos linked.

---

<div class="post-metadata">

**Author:** ![jake\_b](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@jake\_b](https://forum.ionicframework.com/u/jake_b)\
**Post date:** [April 22, 2017, 12:20am UTC](https://forum.ionicframework.com/t/toggle-triggers-ionchange-when-opening-page/87400/4 "2017-04-22T00:20:15Z")

</div>

Thanks for the quick reply guys!

Unfortunately I’m fairly new to Ionic and Angular/Javascript, would you be able to give me a quick example so I could see how to implement it please?
