Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 4 - Pass Data BACK from Popover without dismissing

In Ionic 4, I would like to pass data from Popover controller to the view page.

I am able to get the data onDismiss() but I would like to do it without exiting the popover.

Below is the code snippet I tried onDismiss() and it worked.

Do we any other popover methods or state changes that can be captured

Page

async presentPopover(opts) {

    console.log(opts);
    const popover = await this.popoverController.create({
      component: RouteDetailsPopoverComponent,
      componentProps: {
        viewType: this.viewType
      },
      event: opts.event
    });

    popover.onDidDismiss()
    .then((result) => {
      console.log(result['data']);
      this.viewType = result['data'];
    });

    return await popover.present();
}

And here's the popover component

changeRouteDetailView(mode: View) {
    this.viewType = mode;
    this.popCtrl.dismiss(this.viewType);
}

Without dismissing the popover, can I pass the data back?

like image 912
PKS Avatar asked Nov 26 '18 22:11

PKS


People also ask

How do you dismiss popover in ionic 4?

To dismiss the popover after creation, call the dismiss() method on the Popover instance. The popover can also be dismissed from within the popover's view by calling the dismiss() method on the ViewController. The dismiss() call accepts an optional parameter that will be passed to the callback described as follows.

How do you use popover in ionic 4?

To present a popover, call the present method on a popover instance. In order to position the popover relative to the element clicked, a click event needs to be passed into the options of the the present method. If the event is not passed, the popover will be positioned in the center of the viewport.

How many ways can you add the popover in ionic framework?

There are two ways to use ion-popover : inline or via the popoverController .


1 Answers

Into the page you call the popover component, type this after 'create()' & 'present()' methods to use the popover:

const { data } = await popover.onDidDismiss();

'data' will storage the value you sent from popover component in the page you called the popover component.

At the same time, in the popover component you need to sent the data to the page. Use this line code inside the method you required to return from the popover:

this.popoverCtrl.dismiss({ data_you_sent });

This method, dismiss(), return data (in case you sent) and also close the popover.

like image 197
Yair Abad Avatar answered Sep 28 '22 11:09

Yair Abad