Skip to content

Commit d1cfe7b

Browse files
Merge pull request #1 from SyncfusionExamples/903218-ContextMenuSample
903218-Updated Angular Context Menu Getting Started Sample
2 parents 33528d6 + d004e00 commit d1cfe7b

16 files changed

+376
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
# getting-started-with-the-angular-context-menu-component
2-
A quick-start project that helps you to configure the context menu component with a few of its basic features like item binding, icons, multilevel nesting, navigation links, animation, and customization.
1+
# Getting Started with the Angular Context Menu Component
2+
A quick-start project that helps you to configure the context menu component with a few of its basic features like item binding, icons, multilevel nesting, navigation links, animation, and customization.
3+
4+
Refer to the following documentation to learn about the Angular Context Menu component:
5+
https://ej2.syncfusion.com/angular/documentation/context-menu/getting-started
6+
7+
Check out this online example of the Angular Context Menu component:
8+
https://ej2.syncfusion.com/angular/demos/#/bootstrap5/context-menu/default
9+
10+
## Project prerequisites
11+
Make sure that you have the compatible versions of [Visual Studio Code](https://code.visualstudio.com/download ) and [NodeJS](https://nodejs.org/en/download) or later version in your machine before starting to work on this project.
12+
13+
## How to run this application
14+
To run this application, you need to first clone the `getting-started-with-the-angular-context-menu-component` repository and then open it in Visual Studio Code. Now, simply build and run your project using `npm start` command to view the output.

angular.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"angular-contextmenu-getting-started": {
7+
"projectType": "application",
8+
"schematics": {},
9+
"root": "",
10+
"sourceRoot": "src",
11+
"prefix": "app",
12+
"architect": {
13+
"build": {
14+
"builder": "@angular-devkit/build-angular:application",
15+
"options": {
16+
"outputPath": "dist/angular-contextmenu-getting-started",
17+
"index": "src/index.html",
18+
"browser": "src/main.ts",
19+
"polyfills": [
20+
"zone.js"
21+
],
22+
"tsConfig": "tsconfig.app.json",
23+
"assets": [
24+
{
25+
"glob": "**/*",
26+
"input": "public"
27+
}
28+
],
29+
"styles": [
30+
"src/styles.css"
31+
],
32+
"scripts": []
33+
},
34+
"configurations": {
35+
"production": {
36+
"budgets": [
37+
{
38+
"type": "initial",
39+
"maximumWarning": "500kB",
40+
"maximumError": "1MB"
41+
},
42+
{
43+
"type": "anyComponentStyle",
44+
"maximumWarning": "2kB",
45+
"maximumError": "4kB"
46+
}
47+
],
48+
"outputHashing": "all"
49+
},
50+
"development": {
51+
"optimization": false,
52+
"extractLicenses": false,
53+
"sourceMap": true
54+
}
55+
},
56+
"defaultConfiguration": "production"
57+
},
58+
"serve": {
59+
"builder": "@angular-devkit/build-angular:dev-server",
60+
"configurations": {
61+
"production": {
62+
"buildTarget": "angular-contextmenu-getting-started:build:production"
63+
},
64+
"development": {
65+
"buildTarget": "angular-contextmenu-getting-started:build:development"
66+
}
67+
},
68+
"defaultConfiguration": "development"
69+
},
70+
"extract-i18n": {
71+
"builder": "@angular-devkit/build-angular:extract-i18n"
72+
},
73+
"test": {
74+
"builder": "@angular-devkit/build-angular:karma",
75+
"options": {
76+
"polyfills": [
77+
"zone.js",
78+
"zone.js/testing"
79+
],
80+
"tsConfig": "tsconfig.spec.json",
81+
"assets": [
82+
{
83+
"glob": "**/*",
84+
"input": "public"
85+
}
86+
],
87+
"styles": [
88+
"src/styles.css"
89+
],
90+
"scripts": []
91+
}
92+
}
93+
}
94+
}
95+
},
96+
"cli": {
97+
"analytics": false
98+
}
99+
}

package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "angular-contextmenu-getting-started",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"ng": "ng",
6+
"start": "ng serve",
7+
"build": "ng build",
8+
"watch": "ng build --watch --configuration development",
9+
"test": "ng test"
10+
},
11+
"private": true,
12+
"dependencies": {
13+
"@angular/animations": "^18.0.0",
14+
"@angular/common": "^18.0.0",
15+
"@angular/compiler": "^18.0.0",
16+
"@angular/core": "^18.0.0",
17+
"@angular/forms": "^18.0.0",
18+
"@angular/platform-browser": "^18.0.0",
19+
"@angular/platform-browser-dynamic": "^18.0.0",
20+
"@angular/router": "^18.0.0",
21+
"@syncfusion/ej2-angular-navigations": "^26.2.10",
22+
"rxjs": "~7.8.0",
23+
"tslib": "^2.3.0",
24+
"zone.js": "~0.14.3"
25+
},
26+
"devDependencies": {
27+
"@angular-devkit/build-angular": "^18.0.7",
28+
"@angular/cli": "^18.0.7",
29+
"@angular/compiler-cli": "^18.0.0",
30+
"@types/jasmine": "~5.1.0",
31+
"jasmine-core": "~5.1.0",
32+
"karma": "~6.4.0",
33+
"karma-chrome-launcher": "~3.2.0",
34+
"karma-coverage": "~2.2.0",
35+
"karma-jasmine": "~5.1.0",
36+
"karma-jasmine-html-reporter": "~2.1.0",
37+
"typescript": "~5.4.2"
38+
}
39+
}

public/favicon.ico

14.7 KB
Binary file not shown.

src/app/app.component.css

Whitespace-only changes.

src/app/app.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="container">
2+
<div id="target">
3+
Right click / Touch hold to open the ContextMenu
4+
</div>
5+
<ejs-contextmenu #contextmenu target='#target' [items]='menuItems' showItemOnClick="true"
6+
[animationSettings]="animation" (beforeItemRender)="itemBeforeEvent($event)" (created)="onCreated()">
7+
</ejs-contextmenu>
8+
</div>

src/app/app.component.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { AppComponent } from './app.component';
3+
4+
describe('AppComponent', () => {
5+
beforeEach(async () => {
6+
await TestBed.configureTestingModule({
7+
imports: [AppComponent],
8+
}).compileComponents();
9+
});
10+
11+
it('should create the app', () => {
12+
const fixture = TestBed.createComponent(AppComponent);
13+
const app = fixture.componentInstance;
14+
expect(app).toBeTruthy();
15+
});
16+
17+
it(`should have the 'angular-contextmenu-getting-started' title`, () => {
18+
const fixture = TestBed.createComponent(AppComponent);
19+
const app = fixture.componentInstance;
20+
expect(app.title).toEqual('angular-contextmenu-getting-started');
21+
});
22+
23+
it('should render title', () => {
24+
const fixture = TestBed.createComponent(AppComponent);
25+
fixture.detectChanges();
26+
const compiled = fixture.nativeElement as HTMLElement;
27+
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, angular-contextmenu-getting-started');
28+
});
29+
});

src/app/app.component.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Component, ViewChild } from '@angular/core';
2+
import { RouterOutlet } from '@angular/router';
3+
import { MenuItemModel } from '@syncfusion/ej2-navigations';
4+
import { ContextMenuComponent, ContextMenuModule, MenuEventArgs } from '@syncfusion/ej2-angular-navigations'
5+
6+
@Component({
7+
selector: 'app-root',
8+
standalone: true,
9+
imports: [RouterOutlet, ContextMenuModule],
10+
templateUrl: './app.component.html',
11+
styleUrl: './app.component.css'
12+
})
13+
export class AppComponent {
14+
@ViewChild('contextmenu')
15+
public contextmenu?: ContextMenuComponent;
16+
17+
public menuItems: MenuItemModel[] = [
18+
{
19+
text: 'Cut',
20+
iconCss: 'e-icons e-cut'
21+
},
22+
{
23+
text: 'Copy',
24+
iconCss: 'e-icons e-copy'
25+
},
26+
{
27+
text: 'Paste',
28+
iconCss: 'e-icons e-paste',
29+
// items: [
30+
// {
31+
// text: 'Merge Formatting'
32+
// },
33+
// {
34+
// text: 'Keep Source Formatting'
35+
// }
36+
// ]
37+
},
38+
{
39+
text: 'Navigate',
40+
url: 'https://ej2.syncfusion.com/angular/documentation/context-menu/getting-started'
41+
}
42+
];
43+
44+
public animation = {
45+
effect: 'FadeIn',
46+
duration: 800
47+
};
48+
public itemBeforeEvent(args: MenuEventArgs) {
49+
args.element.classList.add('custom');
50+
}
51+
52+
onCreated(): void {
53+
debugger;
54+
(this.contextmenu as ContextMenuComponent).enableItems(['Copy'], false);
55+
}
56+
}

src/app/app.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
2+
import { provideRouter } from '@angular/router';
3+
4+
import { routes } from './app.routes';
5+
6+
export const appConfig: ApplicationConfig = {
7+
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes)]
8+
};

src/app/app.routes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Routes } from '@angular/router';
2+
3+
export const routes: Routes = [];

0 commit comments

Comments
 (0)