Ionic2 - Popover (ORIGINAL EXCEPTION: TypeError: Cannot read property 'create' of undefined)


#1

I am getting the bellow error when I tried to implement Popover:

ORIGINAL EXCEPTION: TypeError: Cannot read property ‘create’ of undefined

Here is my code:

import {Popover, Page, NavController, MenuController, NavParams} from 'ionic-angular';
@Component({
  template: 'This is a popover'
})
class MyPopover{}

export class HomePage {
  constructor(nav, http, navParams) {}
//PopOver
 showPopover(ev){
    let popover = Popover.create(MyPopover);
    this.nav.present(popover, {
      ev: ev
    })
  }}

Anyone why I am getting this, I believe that there is an issue while importing ‘Popover’ as I am doing the below just after importing Popover:

console.log("Popover object : ",{Popover})

I am getting undefined so mostly the issue is there.


#2

I’m concerned that you’re importing Page. It was removed in the version that added the popover component.


#3

Hmm, other than missing the component annotation for the main class, I don’t seen anything off. Using this, it works fine for me

import {Component} from '@angular/core';
import {NavController, Popover} from 'ionic-angular';
@Component({
  template: 'This is a popover'
})
class MyPopover{}


@Component({
  templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
  constructor(private navController: NavController) {
  }

  showPopover(ev){
    let popover = Popover.create(MyPopover);
    this.navController.present(popover, {
      ev: ev
    })
  }
}