How do I check if ionic popover is opened or closed


#1

I want to know how to check whether ionic popover is closed or opened using if statements. My current code
doesn’t work. Below is my code:

 presentPopover(event: Event) {
    this.popover = this.popoverCtrl.create(PopoverPage);
    this.popover.present({ ev: event });

  }

if(this.popover)
{
//condition goes here
}
else
{
// condition goes here
}


#2

Can you back up a bit and explain what you’re fundamentally trying to achieve? I think storing popovers (and alerts and loading indicators and so on) in object properties is a mistake, because it facilitates doing things with them that you don’t want to do (reusing them, double-dismissing them).


#3

I want to close the opened popover when the back button is pressed. and if the popover is closed, I want to minimize the app then when back button is pressed


#4

In that case, what I would do is to register a back button action that dismisses the popover at the time the popover is presented, and in the popover’s onDidDismiss() unregister that action. You can have multiple back button actions registered, and use the priority level to have the “kill popover” one take precedence over the “minimize app” one while the popover is open. Does that make sense?


#5

I need help with the code to check whether the popover is opened or closed


#6

You don’t need to check that. The popover knows. If its onDidDismiss() hasn’t been called yet, then it’s open, so unregister the back button action that closes the popover in said onDidDismiss().


#7

Can u pls help me with some code because I am confused


#8

can u pls help me with some code because I am confused now


#9

Something like this (untested):

export class AppComponent {
  constructor(plat: Platform) {
    plat.ready().then(() => {
      plat.registerBackButtonAction(() => minimizeApp());
    });
  }
}

export class SomePage {
  constructor(private _plat: Platform, private _popovers: PopoverController) {}

  popPopover(): void {
    let popover = this._popovers.create();
    let doDismiss = () => popover.dismiss();
    let unregBackButton = this._plat.registerBackButtonAction(doDismiss, 5);
    popover.onDidDismiss(unregBackButton);
    popover.present();
  }
}

#10

I want to close the popover with the back button when the popover is open.
on the other hand, when the popover is already closed, then on pressing the backbutton, the app shoud be minimized.
That is how the popover in whatsapp works. U can check it out


#11

No sense this makes.


#12

Sorry
I want to close the popover with the back button when the popover is open.
on the other hand, when the popover is already closed, then on pressing the backbutton, the app shoud be minimized.
That is how the popover in whatsapp works. U can check it out


#13

Please explain how my code does not meet your needs, and stop telling me to install other apps. I have zero desire to do so.


#14

your code can minimize the app when the pop up is closed. but I want the popover to be closed with the back button when the popover is opened . After closing the popover with the back button, when the back button is pressed again then it should minimize the app


#15

What you describe is precisely how the code is supposed to function. Did you actually try it? What happened?


#16

Thanks man…tried the code. It works perfectly