Tutorialsplane

Ionic Popover


Ionic Popover : The popover is basically a view which is used to provide additional information of element when user hovers, clicks or performs some action. Content which needs to show on popover keep them inside the <ion-popover-view> tag. Here in this tutorial we are going to explain Ionic Popover with example and demo.


Ionic Popover

Let us first create a template and add the popover view inside it. Here we are going to create a button and call a function on click event.

Popover Html Part-

Here is html part of popover in ionic.

Ionic Popover:



<div><button>Popover</button></div>



In the above example we have created a button and called a function openPopover on click event. We will create this function in next step. We have created template with id test-popover.html which we will call to show the popover content on button click.  <ion-popover-view> tag is used to create popover view which contains the title & content etc.

Popover Controller Part-

Here is controller part of popover in ionic-

Ionic Popover Example:

 

Try it »

The above controller has $ionicPopover which is required for ionic popover. The function openPopover is used to trigger the event to show the popover. You can call function closePopover to close the popover. The Controller code also contains the events based actions such as if you want to perform some action on popover hidden or popover removed. You can add event based action in the above example also.

If you run the above example it will produce output something like this-

Note :Make sure you have imported the service $ionicPopover in controller as in above example.

Methods-

Following methods are available in Ionic Popover-

1. fromTemplate()
2. fromTemplateUrl().

fromTemplate(templateString, options):

fromTemplateUrl(templateUrl, options):


More About Ionic Popover

Let us Customize the popover.


Add icon in Ionic Popover

Let us add icon in popover template –

Popover Html Part-

Here is html part of popover in ionic.

Ionic Popover:



<div><button>Popover</button></div>



Try it »

In the above example we have added an icon and added custom style for the position of icon. You can also add your own style to manage the icon position and size.

Add Animation in Ionic Popover : slide In Up

You can add the animation in popover simply as below –

Ionic Add Animation in Popover: slide In Up

 

Try it »

The above example will show the popover with the slide in up effect. You can also add other animation effects that ionic supports.

Change Background of Popover

You can add your custom css style to change the background color-

Change Background of Popover

<ion-popover-view class="my-popover">
    <ion-header-bar>
      <h1 class="title">Popover Title</h1>
    </ion-header-bar>
    <ion-content>
	<p class="amp-wp-inline-8c102bef06fb1d44567ff992d8d49ebc">
      Hello World!
	  Welcome to Tutorialsplane.com!
	</p>
    </ion-content>
  </ion-popover-view>

Try it »

The above example will show the popover with the yellow color and text color in #333.

Note : If you want to change the default color and background color override the class .popover. example .popover {color:green; background:yellow;}. It will change the default color & background everywhere in the application so make sure before you override this class.

Change Background Color of Backdrop of Popover

You can override the default background of backdrop of popover by overriding the class .popover-backdrop. So now let us check how it works-

Change Background Color of Backdrop of Popover


Try it »

As you see we have added custom background with important style in .popover-backdrop class because we have to override the default background and replace with our custom background. The above example will show the popover backdrop with the custom background color.

You can customize the popover in ionic as per your need. You can also override the default position of the popover. Most of the time we are concerned about the height & width of the popover you can override the height & width also by adding custom class in wrapper or you can directly override main popover class.

Tip : Make your application more beautiful by customizing the ionic popover. Overriding the core css is proper way so do not modify core files.

Ionic Tutorials

Ionic Components

Javascript Components