×

Ionic Popover

The Ionic popover is a small dialog box that displays at the top of the screen. It can be used for anything, but it is usually used for a button, an action, a pointer, which is similar to the ionic model and action sheets work. The Ionic popover allows the user to present and gather the information easily. The popover is commonly used in the following situations, which are given below:

  • Popover shows more information about the current view.
  • You can select the generally used tools or configuration in the application.
  • Ionic popover contains a list of actions that perform in the current view.

Popover Controller

Popover components programmatically controlled by the popover controller. It can be used to create or dismiss the popover. If you want to create or dismiss the popover, you can use the create() and dismiss() method in the ionic application.

Present() Method

The present() method is used to display the popover on the popover controller instance. If you want to set the position of the popover, it is required to pass a click event in the present() method. If you have not passed any click event, the popover will be displayed at the center of the current page of the screen.

Dismiss() Method

The dismiss() method is used to dismiss the popover after its creation on the popover controller instance. After calling the dismiss() method on the view controller, the popover will be dismissed.

Let us see step by step process how a data passes from page to the popover component.

Step 1: Create a new project in ionic. You can select the blank app template to create a new project.

Step 2: Create a popover custom component in the project. The main purpose of creating a component is to show the notifications of new messages only. To create a component, run the following command:

$ ionic g page popovercomponent

Step 3: After executing the above command, it will create the popover components. Now, you can add the code in the popover components according to your requirements, as shown below:

Popovercomponent.page.html

<ion-content padding>
   <ion-grid>
     <ion-row><ion-col>This is an ionic popover example.</ion-col></ion-row>
     <ion-row><ion-col><ion-button color="success" expand="block" (click)="ClosePopover()">Ok</ion-button></ion-col></ion-row>
   </ion-grid> 
 </ion-content> 

Step 4: In this step, open the app.module.ts file and import the popover components, as shown below:

App.module.ts

import { NgModule } from
'@angular/core';  
 import { BrowserModule } from '@angular/platform-browser';  
 import { RouteReuseStrategy } from '@angular/router';  
 import { IonicModule, IonicRouteStrategy } from '@ionic/angular';  
 import { SplashScreen } from '@ionic-native/splash-screen/ngx';  
 import { StatusBar } from '@ionic-native/status-bar/ngx';  
 import { AppComponent } from './app.component';   
 import { AppRoutingModule } from './app-routing.module';  
 import { PopovercomponentPageModule } from './popovercomponent/popovercomponent.module';  
 @NgModule({  
   declarations: [AppComponent],  
   entryComponents: [],   
   imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, PopovercomponentPageModule],  
   providers: [  
     StatusBar,  
     SplashScreen,  
     { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }  
   ],  
   bootstrap: [AppComponent]  
 })  
 export class AppModule {}   

Step 5: Next, open the popovercomponent.page.ts file and write the following code, which is given below:

Popovercomponent.page.ts

import { Component, OnInit } from
'@angular/core';
 import {PopoverController} from '@ionic/angular';
 @Component({
   selector: 'app-popovercomponent',
   templateUrl: './popovercomponent.page.html',
   styleUrls: ['./popovercomponent.page.scss'],
 })
 export class PopovercomponentPage implements OnInit {
   constructor(private popover:PopoverController) {} 
   ngOnInit() {
   }
   ClosePopover()
   {
     this.popover.dismiss();
   }
 } 

Step 6: Next, open the home.page.ts file and create the CreatePopOver() function by using the following code.

Home.page.ts

import { Component } from
'@angular/core';  
 import { PopoverController } from '@ionic/angular';  
 import { PopovercomponentPage } from '../popovercomponent/popovercomponent.page';  
 @Component({  
   selector: 'app-home',  
   templateUrl: 'home.page.html',  
   styleUrls: ['home.page.scss'],  
 })  
 export class HomePage {  
   constructor(private popover:PopoverController) 
   {
    }  
   CreatePopover()
   {
     this.popover.create({component:PopovercomponentPage,
     showBackdrop:false}).then((popoverElement)=>{
       popoverElement.present();
     })
   }
   } 

 Step 7: Now, open the home.page.html file and write the code, which is shown below:

Home.page.html

<ion-header>  
   <ion-toolbar color="primary">  
     <ion-title>Ionic Popover Example</ion-title>  
   </ion-toolbar>  
 </ion-header>  
 <ion-content class="padding" color="light">  
   <h1>Popover Notification</h1>  
   <ion-button color="danger" (click)="CreatePopover()">Open Popover</ion-button>
 </ion-content> 

Output: After executing this code, you will get the following output:

Ionic Popover

When you click on the Open Popover button, it shows the notification popover. After that, when you click on the Ok button then the notification popover will be closed, as shown below:

Ionic Popover

Related Topics

Ionic Editors

Editors are software programs that permit the users to create and edit the text files. In the development field, editors are usually used to create the source code editors that includes many specific...

3 minutes read.

Ionic Checkbox

Ionic Checkbox Ionic Checkbox is nearly the same as a toggle. It can be placed in an ionic element or used as a separate checkbox. It is designed differently for every platform, such...

2 minutes read.

Ionic Navigation and Routing

The latest version (ionic 4) of the ionic framework, no longer limited to the angular. In Ionic 4, you can create an ionic project in different front-end frameworks such as Vue.js, React.js, and...

6 minutes read.

Ionic Cards

Ionic Cards: Ionic cards are a standard part of the user interface that acts as an entry point for more specific information. These are the best components for displaying information...

4 minutes read.

Ionic Toolbar

A toolbar is a general toolbar that can be used in an application such as a header, sub-header, footer, or even a sub-footer. Because the ion-toolbar is flexbox-dependent, no matter how many toolbars...

3 minutes read.

Ionic Popover

The Ionic popover is a small dialog box that displays at the top of the screen. It can be used for anything, but it is usually used for a button, an action,...

4 minutes read.

Ionic Contents

Ionic Contents The content component provides an easy-to-use content area with some useful ways to control the scrollable region. There should be only one content in one view. Content, along with several other Ionic...

2 minutes read.

Ionic Select

The Ion Selection component is similar to the HTML <select> element. However, the Ionic Selection component makes it easy for users to categorize and choose the preferred option or other options. You must...

3 minutes read.

Ionic vs Apache Cordova

Ionic Vs Apache Cordova Ionic and Cordova are two popular technology going on in the market for mobile application development. The combination of these two technologies creates a development platform that is known as...

3 minutes read.

Ionic Camera

Hybrid mobile applications can make very quickly, but sometimes it becomes a challenge to get the features that access the hardware such as GPS, storage, file storage, cameras, and networks. Cordova offers plugins...

4 minutes read.

Ionic Actionsheet

Ionic Actionsheet The Action sheet is a dialog box that displays a group of options. It is shown on the top of the application content and must be dismissed manually before the user can resume...

3 minutes read.

Ionic Range

The Range slider lets users choose from a range of values by moving the slider knob. You can accept two knobs, but by default, one-knob controls the range value. Range labels You can put down on...

2 minutes read.

Ionic Refresher

Refresher means updating the currently showing page so that the user can see the latest view. It is also known as re-loading in web technology. It provides a pull- to-refresh feature on a...

4 minutes read.

Ionic progress bar

The ionic progress bar element is a horizontal progress bar used to visualize the progression of operation and activity. You can use the <ion-progress-bar> component to create a progress bar in the ionic...

4 minutes read.

Ionic Geolocation

In today’s time, the mobile location plays an essential role in the mobile application. The Ionic Cordova geolocation plugin provides information about the location of the device, like as latitude and longitude. The...

5 minutes read.

Ionic Colors

Ionic Colors Before we start with the actual elements available in the Ionic frame, let's understand a little bit how Ionic uses colors for different elements. Ionic Color Classes Ionic framework is a set of nine predefined...

3 minutes read.

Ionic framework Installation

Installation of Ionic Before proceeding with the ionic application, you'll need to install node.js and NPM (Node Package Manager), the code editor, and Ionic CLI. Installation of node.js and NPM These are the primary...

5 minutes read.

Ionic vs PhoneGap

Ionic Vs PhoneGap Ionic and PhoneGap are both used to develop the mobile application. Both Frameworks are used in large enterprises by the developers. Here, we are going to compare the important differences between ionic...

3 minutes read.

Ionic Input

Ionic Input Inputs are necessary to collect and process user inputs securely. To be easy for users to communicate, they must follow the process and communication guidelines for each platform. It is a...

3 minutes read.

Ionic Loading

The ionic loader is an overlay that can be used to indicate activity, the user interaction while blocking. The ionic loader shows on the top of the app content, and it can...

5 minutes read.