$ionicPopup close is not working


#1

Hi Guys,

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

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

console.log($ionicPopup)

Shows

Is there anything I’m missing out?

Thanks in advance.


#2

read the documentation carefully how the popup service works:
http://ionicframework.com/docs/api/service/$ionicPopup/

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();

#3

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


#4

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.


#5

@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.


#6

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!


#7

@benglter

Thanks for the help. It worked like a charm.


#8

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();