Ionic Popover

Facebooktwitterredditpinterestlinkedinmailby feather

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:

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

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

App.module.ts

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

Popovercomponent.page.ts

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

Home.page.ts

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

Home.page.html

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
Facebooktwitterredditpinterestlinkedinmailby feather