$ionicPopup.confirm(, then, res = undefined always


#1

Hello. I can not differ results of a confirm box. then() is always invoked with the undefined result.

  $ionicPopup.confirm({
                  template: $filter('translate')('confirm:delete'),
                  buttons: [{text: $filter('translate')('label:cancel')}, {text: $filter('translate')('label:ok')}]
                })
                .then(function(res) {
                  console.log(res);
                  if(res) {
                    Cars.delete_load(load_uuid, car_uuid);
                    Cars.save();
                    $state.go('load.index', {car_uuid: car_uuid});
                  }
                });

Thank you.


#2

You can add onTap to button, and return your desired value for ‘res’

$ionicPopup.confirm({
              template: $filter('translate')('confirm:delete'),
              buttons: [{
                  text: $filter('translate')('label:cancel'),
                  onTap: function(e) {return 'cancel'}
               },
               {
                  text: $filter('translate')('label:ok')
               }]
            })
            .then(function(res) {
              console.log(res);
              if(res == 'cancel') {
                Cars.delete_load(load_uuid, car_uuid);
                Cars.save();
                $state.go('load.index', {car_uuid: car_uuid});
              }
            });

#3

Thank you. I’ve done so.