We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get started easily with Syncfusion Angular 11 Context Menu?

Platform: Angular - EJ 2 |
Control: ContextMenu

A quick start project that helps you to create an Angular 11 Context Menu with a minimal code configurations.

The following section explains you how to create a simple angular 11 Context Menu component.

Prerequisites

 

Before start, we need following items to create Angular Context Menu in Angular 11 application

Dependencies

 

The angular 11 Context Menu is created from the Syncfusion ej2-angular-navigations package from npmjs, which are distributed in npm as @syncfusion scoped packages.

Creating Angular Project

 

  1. Install Angular cli 11 using following command.

 

npm install -g @angular/cli@11.2.3

 

Note:

If you would like to follow and run the application in Angular 6 or Angular 5 or Angular 4, you need to replace the CLI command version number with the corresponding angular version number.

 

npm install -g @angular/cli@<CLI VERSION>

 

 

  1. Create a new Angular 11 project using angular cli and navigate to that folder.

 

ng new angular11-app

cd angular11-app

 

Adding Angular Context Menu

 

  1. After running the Angular 11 application successfully, configure the Angular Context Menu in this application. Install Angular Context Menu and EJ2 package using following command. 

 

npm install @syncfusion/ej2-angular-navigations --save

 

The --save command will instruct the NPM to include a Context Menu package inside the dependencies section of the package.json.

  1. Import Context Menu from installed package.
  2. Import and inject the other required modules within the providers section of app.module.ts.

 

import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';

import { ContextMenuModule } from '@syncfusion/ej2-angular-navigations';

import { AppComponent } from './app.component';

import { enableRipple } from '@syncfusion/ej2-base';

 

enableRipple(true);

 

@NgModule({

  declarations: [

    AppComponent

  ],

  imports: [

    BrowserModule,

    ContextMenuModule

  ],

  providers: [],

  bootstrap: [AppComponent]

})

export class AppModule {}

 

  1. Add the given below angular context menu’s styles in styles.css.

 

@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";

@import "../node_modules/@syncfusion/ej2-base/styles/material.css";

 

/* Context Menu target */

#target {

    border: 1px dashed;

    height: 150px;

    padding: 10px;

    position: relative;

    text - align: justify;

    color: gray; 

    user - select: none;

}

 

  1. Add the angular Context Menu component in app.component.ts.

 

import { Component } from '@angular/core';

import { MenuItemModel } from '@syncfusion/ej2-navigations';

 

@Component({

    selector: 'app-root',

    template`<div id="target">Right click / Touch hold to open the ContextMenu</div>

<ejs-contextmenu id='contextmenu' target='#target' [items]= 'menuItems'></ejs-contextmenu>`

})

export class AppComponent {

public menuItems: MenuItemModel[] = [

    {

        text: 'Cut'

    },

    {

        text: 'Copy'

    },

    {

        text: 'Paste'

    }];

}

 

  1. Now serve the application using following command.

 

ng serve 

 

Once the files are compiled successfully, it will serve the site at localhost:4200

Screenshot:

Context-Menu

Rendering Items with Separator

 

The Separators are the horizontal lines used to separate the menu items. You can enable separators to group the menu items using the separator property. In the following sample Cut, Copy, and Paste menu items are grouped using separator property.

[app.component.ts]

import { Component } from '@angular/core';

import { MenuItemModel } from '@syncfusion/ej2-navigations;

 

@Component({

    selector: 'app-root',

    template`<div id="target">Right click / Touch hold to open the ContextMenu</div>

<ejs-contextmenu id='contextmenu' target='#target' [items]= 'menuItems'></ejs-contextmenu>`

})

export class AppComponent {

public menuItems: MenuItemModel[] = [

    {

        text: 'Cut'

    },

    {

        text: 'Copy'

    },

    {

        text: 'Paste'

    },

    {

        separator: true

    },

    {

        text: 'Font'

    },

    {

        text: 'Paragraph'

    }];

}

 

Screenshot:

Separator

Summary

 

Refer to our documentation and online samples for more features. If you have any queries, please let us know in comments below.  You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!

2X faster development

The ultimate Angular UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile