API
To show or hide the Popup programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the Popup, respectively.
With Angular, Vue or React, use a different technique. Bind the visible property of the Popup UI component to a component property. After that, change this component property, and the Popup will appear or disappear.
- <dx-popup
- title="Popup Title"
- [(visible)]="isPopupVisible">
- <div *dxTemplate="let data of 'content'">
- <p>Popup content</p>
- </div>
- </dx-popup>
- <dx-button
- text="Show the Popup"
- (onClick)="isPopupVisible = true">
- </dx-button>
- <dx-button
- text="Hide the Popup"
- (onClick)="isPopupVisible = false">
- </dx-button>
- import { DxPopupModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- isPopupVisible: boolean = false;
- }
- @NgModule({
- imports: [
- // ...
- DxPopupModule
- ],
- // ...
- })
User Interaction
The Popup can also be hidden when a user clicks outside it. To control this behavior of the Popup, use the closeOnOutsideClick property.
- <dx-popup
- title="Popup Title"
- [(visible)]="isPopupVisible"
- [closeOnOutsideClick]="true">
- </dx-popup>
- import { DxPopupModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- isPopupVisible: boolean = true;
- }
- @NgModule({
- imports: [
- // ...
- DxPopupModule
- ],
- // ...
- })
Events
To execute certain commands before or after the Popup 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.
- <dx-popup ...
- (onShowing)="popup_showing($event)"
- (onShown)="popup_shown($event)"
- (onHiding)="popup_hiding($event)"
- (onHidden)="popup_hidden($event)">
- </dx-popup>
- import { DxPopupModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- popup_showing (e) {
- // Handler of the "showing" event
- }
- popup_shown (e) {
- // Handler of the "shown" event
- }
- popup_hiding (e) {
- // Handler of the "hiding" event
- }
- popup_hidden (e) {
- // Handler of the "hidden" event
- }
- }
- @NgModule({
- imports: [
- // ...
- DxPopupModule
- ],
- // ...
- })
If you are going to change event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to the events using the on(eventName, eventHandler) method. This approach is more typical of jQuery.
- const hiddenEventHandler1 = function (e) {
- // First handler of the "hidden" event
- };
- const hiddenEventHandler2 = function (e) {
- // Second handler of the "hidden" event
- };
- $("#popupContainer").dxPopup("instance")
- .on("hidden", hiddenEventHandler1)
- .on("hidden", hiddenEventHandler2);
See Also
- Handle Events: Angular | Vue | React | jQuery | AngularJS | Knockout | ASP.NET MVC 5 | ASP.NET Core
- Popup - Customize the Content
- Popup - Resize and Relocate
- Popup Demos
- Popup API Reference
If you have technical questions, please create a support ticket in the DevExpress Support Center.