# ngx-contextmenu A context menu built with Angular (6) inspired by [ui.bootstrap.contextMenu](https://github.com/Templarian/ui.bootstrap.contextMenu). Bootstrap classes are included in the markup, but there is no explicit dependency on Bootstrap. [Demo](https://isaacplmann.github.io/ngx-contextmenu/) [Stackblitz example](https://stackblitz.com/edit/ngx-contextmenu-example) ## Installation - `npm install ngx-contextmenu @angular/cdk` - import ContextMenuModule.forRoot() into your app module - Make sure to include `` at the top of your `index.html` ## Usage ### Angular 5 support Please use ngx-contextmenu@4.2.0 with Angular 5 projects. ### Template ```html Say hi! Bye, {{item?.name}} Input something: ``` ### Component Code ```js @Component({ ... }) export class MyContextMenuClass { public items = [ { name: 'John', otherProperty: 'Foo' }, { name: 'Joe', otherProperty: 'Bar' } ]; @ViewChild(ContextMenuComponent) public basicMenu: ContextMenuComponent; } ``` ## Context Menu Items - Each context menu item is a `` element with the `contextMenuItem` attribute directive applied. - If the `item` object is used in the context menu item template, the `let-item` attribute must be applied to the `` element. ** Note: ** Make sure to use the `item?.property` syntax in the template rather than `item.property` as the item will be initially `undefined`. - Every context menu item emits `execute` events. The `$event` object is of the form `{ event: MouseEvent, item: any }` where `event` is the mouse click event that triggered the execution and `item` is the current item. - The `divider` input parameter is optional. Items default to normal menu items. If `divider` is `true`, all the other inputs are ignored. - The `passive` input parameter is optional. If `passive` is `true`, the menu item will not emit execute events or close the context menu when clicked. - The `enabled` input parameter is optional. Items are enabled by default. This can be a boolean value or a function definition that takes an item and returns a boolean. - The `visible` input parameter is optional. Items are visible by default. This property enables you to show certain context menu items based on what the data item is. This can be a boolean value or a function definition that takes an item and returns a boolean. - Within the template, you have access to any components and variables available in the outer context. ```html Say hi, {{item?.name}}! With access to the outside context: {{ outsideValue }} ``` ```js public outsideValue = "something"; public isMenuItemType1(item: any): boolean { return item.type === 'type1'; } ``` ## Sub-menus You can specify sub-menus like this: ```html Say... ...hi! ...hola! ...salut! Bye, {{item?.name}} Input something: ``` Notes: 1. The sub `` can not be placed inside the `` that references it. 2. Sub-menus may be nested as deeply as you wish. ## Upgrade from angular2-contextmenu 0.x 1. Change `package.json` to reference `ngx-contextmenu` instead of `angular2-contextmenu` 2. Upgrade to `@angular` 4.x 3. Use `` instead of `