-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: Multiple popups can't be closed (sort of) #3131
Comments
Some kind of timing issue. The result is 3 divs with classes: 'popup-showing active'. The popupStack isn't updated quickly enough, so each new modal isn't aware of the previous ones. |
This issue is still on 1.0.1, I get multiple popups |
I am having the same issue here, I am on 1.5.5 |
This is how i handle it:
|
@sharvit Thanks for your solution, it helps alot! |
This is a common issue that begs for a default solution. Thanks @sharvit EDIT: typo |
@sharvit Thanks for the solution. Opening the popup works, but how can I close it and open another? |
@Florian9-3 that way you can get the close method with the promise: .factory('SecuredPopups', [
'$ionicPopup',
'$q',
function ($ionicPopup, $q) {
var firstDeferred = $q.defer();
firstDeferred.resolve();
var lastPopupPromise = firstDeferred.promise;
// Change this var to true if you want that popups will automaticly close before opening another
var closeAndOpen = false;
return {
'show': function (method, object) {
var deferred = $q.defer();
var closeMethod = null;
deferred.promise.isOpen = false;
deferred.promise.close = function () {
if (deferred.promise.isOpen && angular.isFunction(closeMethod)) {
closeMethod();
}
};
if (closeAndOpen && lastPopupPromise.isOpen) {
lastPopupPromise.close();
}
lastPopupPromise.then(function () {
deferred.promise.isOpen = true;
var popupInstance = $ionicPopup[method](object);
closeMethod = popupInstance.close;
popupInstance.then(function (res) {
deferred.promise.isOpen = false;
deferred.resolve(res);
});
});
lastPopupPromise = deferred.promise;
return deferred.promise;
}
};
}
])
// ...
var alertPopupA = SecuredPopups.show('alert', {
title: 'AAA',
template: 'AAA'
});
var alertPopupB = SecuredPopups.show('alert', {
title: 'BBB',
template: 'BBB'
});
alertPopupA.then(function(res) {
console.log('AAA Finished!');
});
alertPopupB.then(function(res) {
console.log('BBB Finished!');
});
console.log('A is: ' + alertPopupA.isOpen ? 'open' : 'closed');
console.log('B is: ' + alertPopupB.isOpen ? 'open' : 'closed');
alertPopupA.close(); I didn't test it, let me know if its work |
@sharvit Works like a charm. Thanks so much. |
It seems to me that @sharvit's solution only allows for one extra layer of popups. I wanted a generalized solution allowing for an arbitrary amount of popups, and arrived at one which works as follows:
I didn't test this with more than two overlapping popups, but it should work in theory ;) |
+1 |
@ajoslin this issue should be opened again, or at least a workaround should be documented somewhere. Do you know a good place where we can add it ? |
@sharvit thanks !! |
+1 |
Hey guys, I get "TypeError: $ionicPopup[method] is not a function" when I try to implement the factory @sharvit posted. Does anybody have a workaround? |
Hello! Are you all still having this issue? Thanks! |
Hello! As it has been a little while since there was any activity on this issue I will be closing it. Thanks for using ionic! |
@jgw96 yes of course, we have a "dirty" workaround in place (like everyone I think). Do you need something ? May we help ? Did you ask because something change in a new release ? |
am still facing the same issue....can anyone help me to fix this problem.. |
@mushopea |
but am calling the ionic popup using normal js. thanks in advance |
Create factory like @sharvit, paste SecuredPopups in your controller definition and create $scope.popup there.
Now you can call $scope.alertPopupA(); in controller or ng-click="alertPopupA()" in template. |
tanks for ur help 👍 |
Type: bug
Platform: all
The issue only happens when multiple popups are opened in quick succession. In this case, the backdrop div remains visible after the last popup has closed. We've been able to repro the issue on iOS 8 and on the desktop (chrome and IE11).
I've included a short codepen to illustrate the issue.
http://codepen.io/anon/pen/VYXLjv
The text was updated successfully, but these errors were encountered: