Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 3 passing data to popover

I am unable to make it work. The popup calling code is

presentPopover(myEvent){
        //alert('invoke popup')
      let popover = this.popoverCtrl.create(PopoverPage, this.data);
      popover.present(
          {
            ev: myEvent
          }
      );
}

and the part where i need to access currently is:

export class PopoverPage{

  constructor(public viewCtrl: ViewController) {
   // alert('in the popup')  
   //alert(this.data)
  }

So how will the data be avaialbe in the popupover page component ?

like image 628
Vik Avatar asked Jul 14 '17 06:07

Vik


1 Answers

Parameters/data can be passed to the Popover like this

let popover = this.popoverCtrl.create(PopoverPage, {key1:value1, key2: value2});

And then you can use NavParams to retrieve the data passed to the Popover.

    export class PopoverPage{        
      constructor(public navParams:NavParams) {
       console.log(this.navParams.data);
       let value1 = this.navParams.get('key1');
       let value2 = this.navParams.get('key2');
      }
    }

For ionic v4, you can send data using componentProps to pass data and retrieve through navParams.

const popover = await this.popoverController.create({
      component: PopoverPage,
      componentProps:{key1:value1, key2: value2}
    });
    return await popover.present()
like image 105
Suraj Rao Avatar answered Oct 26 '22 11:10

Suraj Rao