How to check if an ionicModal is open?

Asked

Viewed 57 times

0

Hello, How to know if an ionicModal is open? I need to check if an ionicModal is open, in case I need to close it so it doesn’t open two ionicModal at the same time

  • Ionic 1, 2 or 3 ?

  • Ionic framework 1

1 answer

1

According to the documentation, every time you make a call

$ionicModal.fromTemplate(...)
$ionicModal.fromTemplateUrl(...)

will receive a new Promise of ionicModal. The method you are looking for is the isShown.

if (ionicModal.isShown()) { // se a janela está visível ...
    ionicModal.hide(); // fecha ...
}

What can happen is that more than one place may want to create these modals and you will not have access to these references, in this case you need to implement a proper mechanism to control how many modals are open (make a Factory that instantiates these modals and saves the references, or, use the events that the $ionicModal emits) and/or if you want to overwrite a modal.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.