# Popovers in Ionic 4

**URL:** <https://forum.ionicframework.com/t/popovers-in-ionic-4/137426>\
**Category:** Ionic Framework\
**Created:** [August 5, 2018, 2:56pm UTC](https://forum.ionicframework.com/t/popovers-in-ionic-4/137426 "2018-08-05T14:56:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [August 5, 2018, 2:56pm UTC](https://forum.ionicframework.com/t/popovers-in-ionic-4/137426/1 "2018-08-05T14:56:20Z")

</div>

This took me too frikkin long to figure out, so I’m guessing other people might benefit from a writeup. I wanted to migrate a simple popover with a “close” button on the popover message. With ViewController it only required one line. Here’s the cleanest way I’ve found to do this, now that ViewController is gone.

Define the popover. When you do, pass the PopoverController itself as a parameter.

```auto
constructor(private pop: PopoverController) { }

  showPopover(event: Event): Promise<void> {
    return this.pop.create({ component: PopoverPage, ev: event,
                             componentProps: {message: 'passed message', popoverController: this.pop} })
                   .then(popover => popover.present());
  }

```

Note: using async/await instead is fine. I use Promises because they provide more granular control, but it doesn’t matter for this example. The important point here is I am passing `this.pop`.

Then in `PopoverPage`:

```auto
message = '';
  pop: PopoverController;

  constructor(navParams: NavParams) {
    this.message = navParams.get('message');
    this.pop = navParams.get('popoverController');
  }

  close() {
    this.pop.dismiss();
  }

```

The “OK” button in the popover message executes the close function when clicked. That seems to work fine. I’ve run into no issues so far.

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [August 5, 2018, 3:27pm UTC](https://forum.ionicframework.com/t/popovers-in-ionic-4/137426/3 "2018-08-05T15:27:36Z")

</div>

I don’t understand your post yet, sorry. I need the ability to close visible inside the popover message page, so clicking a CLOSE button will close the popover message.

Sample html:

```auto
<div style="white-space: pre-wrap;" padding>{{message}}</div>
<ion-button fill="clear" (click)="close()">OK</ion-button>

```

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [August 5, 2018, 3:29pm UTC](https://forum.ionicframework.com/t/popovers-in-ionic-4/137426/4 "2018-08-05T15:29:46Z")

</div>

My bad, I understand better your post now. I was assuming that you provided the popover a all template and not “just” a msg

Clever solution, well done 🙂

---

<div class="post-metadata">

**Author:** ![dulciepercy](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@dulciepercy](https://forum.ionicframework.com/u/dulciepercy)\
**Post date:** [December 26, 2018, 5:49am UTC](https://forum.ionicframework.com/t/popovers-in-ionic-4/137426/6 "2018-12-26T05:49:10Z")

</div>

Thanks this helps me enormously. I want all my popovers dismiss themselves after 5 seconds, so I’ve added this in the constructor, using the same passed parameter instead of the old view controller.

```auto
 constructor(navParams: NavParams) {
    this.pop = navParams.get('popoverController');
      {// set it to dismiss automatically after 5000ms
        setTimeout(() => {
          this.pop.dismiss();
        }, 5000);
       };
  }

```

---

<div class="post-metadata">

**Author:** ![elso](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@elso](https://forum.ionicframework.com/u/elso)\
**Post date:** [February 22, 2019, 3:47pm UTC](https://forum.ionicframework.com/t/popovers-in-ionic-4/137426/7 "2019-02-22T15:47:48Z")

</div>

Hi,  
could you just skip the usage of the componentProps and inject the PopoverController like you did before?

Within the HostComponent:

```auto
constructor(private pop: PopoverController) { }

  showPopover(event: Event): Promise<void> {
    return this.pop.create({ component: PopoverPage, ev: event,
                             componentProps: {message: 'passed message'} })
                   .then(popover => popover.present());
  }

```

Within the PopoverComponent:

```auto
 constructor(private popoverController: PopoverController) {
      {// set it to dismiss automatically after 5000ms
        setTimeout(() => {
          this.popoverController.dismiss();
        }, 5000);
       };
  }

```

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:26pm UTC](https://forum.ionicframework.com/t/popovers-in-ionic-4/137426/8 "2021-07-19T21:26:07Z")

</div>

Closed on July 19, 2021, 9:26pm UTC


