0

I trying to set local Notification for my ionic cordova app , but when i click on the redirect to home page does not work : this is my controller :

app.controller('notificationCtrl', function($scope, $rootScope, $ionicPlatform, $cordovaLocalNotification, $state){
      $scope.add = function() {
        var alarmTime = new Date();
        alarmTime.setMinutes(alarmTime.getMinutes() + 1);
        $cordovaLocalNotification.add({
            id: 1,
            date: alarmTime,
            message: "Bonjour",
            title: "nouvelle commande",
            autoCancel: true,
            sound: null
        }).then(function () {
            alert("The notification has been set");
        });
    };
     $rootScope.$on('$cordovaLocalNotification:click',
    function (event, notification, state) {
      $state.go('home');
      alert('ok then ');
    });

});

1 Answers1

3

According to Docs, you have to do that inside $ionicPlatform.ready(), The click event will also be called after deviceready if the app wasn't running.

app.controller('NotificationCtrl', function($scope, $rootScope, $ionicPlatform, $cordovaLocalNotification, $state){

 $ionicPlatform.ready(function () {

  $scope.add = function() {
    var alarmTime = new Date();
    alarmTime.setMinutes(alarmTime.getMinutes() + 1);
    $cordovaLocalNotification.add({
        id: 1,
        date: alarmTime,
        message: "Bonjour",
        title: "nouvelle commande",
        autoCancel: true,
        sound: null
    }).then(function () {
        alert("The notification has been set");
    });
  };

  $rootScope.$on('$cordovaLocalNotification:click',
   function (event, notification, state) {
    $state.go('home');
    alert('ok then ');
  });

 });
});