Search code examples
javascriptangularjsionic-frameworkionic-popup

$ionicPopup breaks as state changes in background


I have an interesting situation where I am polling for a location change on a travelling page in my ionic app. When the App detects a location change is by a certain location, it invokes an $ionicPopup.show() alert to see what the user wants to do about it.

My problem is there is a button on the page to move to another state (and cancel the location poll) but if this is pressed at the same time the popup is being invoked, which is easier to do than you think, the popup remains in view but does not contain the buttons to dismiss it. Meanwhile the state has changed in the background to the new page.

What I'm looking for is a way to avoid these both happening at the same time, is there a way I can clear any active $ionicPopup's when the button is pressed?


Solution

  • How to programmatically close $ionicPopup:

    var my_popup = $ionicPopup.show(); // assign the promise to some var
    
    my_popup.close(); // whenever you want to close this popup