<ion-toggle> on-change issue

Hi all,

I’m trying to use an ion-toggle to turn on and off push notifications, as per the following code:

  function pushNotificationChange() {
    if ($scope.pushNotification.checked) {
      alert('turn off');
      //some other function that turns it off will go here
      $scope.pushNotification.checked = false;
    } else {
      alert('turn on');
      //some other function that turns it on will go here
      $scope.pushNotification.checked = true;
    };

See the Pen Toggle: Nightly by Darshan (@darshanp) on CodePen.

What happens is that the toggle is changing the value of pushNotification.checked before the on-change function is called so I can’t turn push notifications on when they are off and vice-versa.

Does anybody have any ideas about how to get around this?