monugt
October 13, 2015, 12:48pm
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.
monugt:
$ionicPopup
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
YayO
October 13, 2015, 1:20pm
3
… or just add a button on your popover, it will close it on default
2 Likes
monugt
October 13, 2015, 7:35pm
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.
monugt
October 13, 2015, 7:45pm
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.
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
monugt
October 14, 2015, 11:48am
7
@benglter
Thanks for the help. It worked like a charm.
1 Like
wggley
April 12, 2018, 11:25pm
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();
1 Like