Angular Popover - Show and Hide the Popover

User Interaction

To specify when the Popover should be shown and hidden, set the showEvent and hideEvent properties. These properties can accept several events at once as well as an object.

HTML
TypeScript
  • <img id="image" src="https://url/to/an/image" />
  • <dx-popover
  • target="#image"
  • showEvent="dxhoverstart"
  • hideEvent="dxhoverend">
  • <div *dxTemplate="let data of 'content'">
  • <p>Popover content</p>
  • </div>
  • </dx-popover>
  • import { DxPopoverModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • // ...
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxPopoverModule
  • ],
  • // ...
  • })

View Demo

The Popover can also be hidden when a user clicks outside it. To control this behavior of the Popover, use the hideOnOutsideClick property.

HTML
TypeScript
  • <img id="image" src="https://url/to/an/image" />
  • <dx-popover
  • target="#image"
  • showEvent="dxhoverstart"
  • hideEvent="dxhoverend"
  • [hideOnOutsideClick]="false">
  • <div *dxTemplate="let data of 'content'">
  • <p>Popover content</p>
  • </div>
  • </dx-popover>
  • import { DxPopoverModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • // ...
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxPopoverModule
  • ],
  • // ...
  • })

API

NOTE
In this article, the Button UI component is used to demonstrate how to show and hide the Popover. This choice is made for purely demonstrational purposes, and you can do the same operations using another UI component following the same guidelines.

To show or hide the Popover programmatically, bind the visible property of Popover to a component property. After that, change the latter property, and the Popover will appear or disappear.

HTML
TypeScript
  • <img id="image" src="https://url/to/an/image" />
  • <dx-popover
  • target="#image"
  • [visible]="isPopoverVisible">
  • <div *dxTemplate="let data of 'content'">
  • <p>Popover content</p>
  • </div>
  • </dx-popover>
  • <dx-button
  • text="Show the Popover"
  • (onClick)="isPopoverVisible = true">
  • </dx-button>
  • <dx-button
  • text="Hide the Popover"
  • (onClick)="isPopoverVisible = false">
  • </dx-button>
  • import { DxPopoverModule, DxButtonModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • isPopoverVisible: boolean = false;
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxPopoverModule
  • ],
  • // ...
  • })

Events

To execute certain commands before or after the Popover was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property when you configure the UI component.

HTML
TypeScript
  • <dx-popover ...
  • (onShowing)="onShowing($event)"
  • (onShown)="onShown($event)"
  • (onHiding)="onHiding($event)"
  • (onHidden)="onHidden($event)">
  • </dx-popover>
  • import { DxPopoverModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • onShowing (e) {
  • // Handler of the "showing" event
  • },
  • onShown (e) {
  • // Handler of the "shown" event
  • },
  • onHiding (e) {
  • // Handler of the "hiding" event
  • },
  • onHidden (e) {
  • // Handler of the "hidden" event
  • }
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxPopoverModule
  • ],
  • // ...
  • })
See Also