Brian Ivander T. P.
Brian Ivander T. P.

Reputation: 485

Ionic Popover showBackdrop: true is not working

I am using ionic 3.9.2.

I am creating a new blank project using PopoverController, but the backdrop is not showing.

This is my home.html:

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  The world is your oyster.
  <p>
    If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will be your guide.
  </p>

  <button ion-button icon-only (click)="presentPopover($event)">
    <ion-icon name="more"></ion-icon>
  </button>
</ion-content>

This is my home.ts:

import { Component } from '@angular/core';
import { NavController, ViewController } from 'ionic-angular';
import { PopoverController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, public popoverCtrl: PopoverController) {

  }

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

}

@Component({
  template: `
    <ion-list>
      <ion-list-header>Ionic</ion-list-header>
      <button ion-item (click)="close()">Learn Ionic</button>
      <button ion-item (click)="close()">Documentation</button>
      <button ion-item (click)="close()">Showcase</button>
      <button ion-item (click)="close()">GitHub Repo</button>
    </ion-list>
  `
})
export class PopoverPage {
  constructor(public viewCtrl: ViewController) {}

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

I have also imported the PopoverPage to app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { PopoverPage } from '../pages/home/home';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    PopoverPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    PopoverPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

My package.json:

"dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/core": "~4.17.0",
    "@ionic-native/splash-screen": "~4.17.0",
    "@ionic-native/status-bar": "~4.17.0",
    "@ionic/storage": "2.2.0",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.26"
  }

I have tried to declare the showBackdrop: true explicitly like this but it is still not working.

presentPopover(myEvent) {
    let popover = this.popoverCtrl.create(PopoverPage, {}, {showBackdrop: true});
    popover.present({
      ev: myEvent
    });
  }

This is the screenshot of my app

My app

I also provide the inspection from the popover component.

inspection

Upvotes: 1

Views: 1926

Answers (1)

Gerson Montenegro
Gerson Montenegro

Reputation: 486

In order to make it work, you have to implement the popOver like this:

MyComponent.ts

    constructor(..., private popOverController: PopoverController){
    ...
    }

    show(){
        this.pop = this.popOverController.create(CustomComponentPage, {}, { showBackdrop: true, cssClass: 'popOverClass' });
        this.pop.present();
    }

And the popOverClass must be implemented in variables.scss file

variables.scss

.popOverClass{
  background-color: #ff00ffaa !important;
}

Upvotes: 1

Related Questions