$ionicPopup close is not working

Hi Guys,

I’m not able to use $ionicPopup.close method. it shows following error,

image

I have injected $ionicPopup to the controller and ionicPopup has been shown on the screen as well.

console.log($ionicPopup)

Shows

image

Is there anything I’m missing out?

Thanks in advance.

read the documentation carefully how the popup service works:

the $ionicPopup-functions return a popup object you need to store. And this object has a function named close

var myPopup = $ionicPopup.show({ ... });
myPopup.close();
1 Like

… or just add a button on your popover, it will close it on default

2 Likes

Thank you @bengtler.

I’ve tried that approach too. It gives the same error as the above example.

I’m using the ionic framework version - driftyco/ionic-bower#1.0.0

Let me know if it helps out.

Thanks again.

@YayO,

Thanks for responding.

I’m trying to close a popup on onPause event. But I realized the close function do not work from same controller too.

Please share your views.

Thank you.

if you are listen on a native javascript and not an angular event your code is executed outside the angularjs context --> the solution: Wrap your AngularJS-Code in your event-callback in $timeout(function () { … });.

e.g.

document.addEventListener('pause', function () {
    $timeout(function () {
        myModal.close();
    });
}, false);

PS: Do not forget to load $timeout in your controller and be sure the pause-event gets triggered!

2 Likes

@benglter

Thanks for the help. It worked like a charm.

1 Like

This error also occurs when using promises:

//It's not working
var myPopup = $ionicPopup.show({ ... })
   .then(function(){
     //something
   });
//close method vanished!
myPopup.close();
//It's working
var myPopup = $ionicPopup.show({ ... });
myPopup.then(function(){
 //something
});
myPopup.close();
1 Like