[SOLVED] Popover dismiss anywhere

Hello,

I have the following code to close all the popovers that are open, before redirecting users to the login page

  constructor(
    private _popoverCtrl: PopoverController
  ) { }

  logout() {
    this._popoverCtrl.dismiss();
  }

This code only works if there is at least one popover open, but if all are closed, then “dismiss ()” throws the following exception

  ERROR Error: Uncaught (in promise): overlay does not exist

Which is fine, but, how else can I close all the popovers in the logout without knowing exactly if they are or are not open

async logout() {
    if (await this._popoverCtrl.getTop()) this._popoverCtrl.dismiss();
}
1 Like

SOLVED

thank you