DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Angular Context Menu - Templates

The ContextMenu component provides full control over the appearance and behavior of menu items across all nesting levels.

Backend API
<div class="label"> Right click an image to display the context menu: </div> <img id="image" alt="product" src="../../../../images/products/5.png" /> <dx-context-menu [dataSource]="dataSource" [width]="200" target="#image" (onItemClick)="itemClick($event)" > <div *dxTemplate="let itemData of 'item'"> <div class="item-template-container"> @if (itemData.icon) { <span [class]="itemData.icon" class="dx-icon"></span> } <span class="dx-menu-item-text">{{ itemData.text }}</span> @if (itemData.items) { <span class="dx-icon-spinright dx-icon"></span> } </div> </div> </dx-context-menu>
import { bootstrapApplication } from '@angular/platform-browser'; import { Component, enableProdMode, provideZoneChangeDetection } from '@angular/core'; import notify from 'devextreme/ui/notify'; import { DxContextMenuModule, type DxContextMenuTypes } from 'devextreme-angular/ui/context-menu'; if (!document.location.host.includes('localhost')) { enableProdMode(); } class ContextMenuItem { text: string; icon?: string; items?: ContextMenuItem[]; } @Component({ selector: 'demo-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], imports: [ DxContextMenuModule, ], }) export class AppComponent { dataSource: ContextMenuItem[] = [{ text: 'Share', icon: 'dx-icon-globe', items: [ { text: 'Facebook' }, { text: 'Twitter' }], }, { text: 'Download', icon: 'dx-icon-download' }, { text: 'Add Comment', icon: 'dx-icon-add' }, { text: 'Add to Favorite', icon: 'dx-icon-favorites' }, ]; itemClick({ itemData: { items, text } }: DxContextMenuTypes.ItemClickEvent<ContextMenuItem>) { if (!items) { notify(`The "${text}" item was clicked`, 'success', 1500); } } } bootstrapApplication(AppComponent, { providers: [ provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }), ], });
::ng-deep .item-template-container { display: flex; align-items: center; gap: 6px; width: 100%; } ::ng-deep .dx-menu-item-text { flex-grow: 1; } ::ng-deep #image { height: 300px; } .label { color: var(--dx-texteditor-color-label); }
<!DOCTYPE html> <html lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> <script src="https://cdn.jsdelivr.net/npm/zone.js@0.16.2/bundles/zone.umd.js"></script> <script src="./bundle.js" type="module"></script> </body> </html>