support for toggling custom context menu (#1683)

* support for toggling custom context menu

* fix unit tests
This commit is contained in:
Denys Vuika
2017-03-03 09:25:08 +00:00
committed by Mario Romano
parent 4ca18bc8f9
commit 2e44550d7f
8 changed files with 30 additions and 14 deletions

View File

@@ -26,6 +26,7 @@ describe('ContextMenuDirective', () => {
beforeEach(() => {
contextMenuService = new ContextMenuService();
directive = new ContextMenuDirective(contextMenuService);
directive.enabled = true;
});
it('should show menu via service', (done) => {

View File

@@ -25,18 +25,23 @@ export class ContextMenuDirective {
@Input('context-menu')
links: any[];
@Input('context-menu-enabled')
enabled: boolean = false;
constructor(private _contextMenuService: ContextMenuService) {
}
@HostListener('contextmenu', ['$event'])
onShowContextMenu(event?: MouseEvent) {
if (event) {
event.preventDefault();
}
if (this.enabled) {
if (event) {
event.preventDefault();
}
if (this.links && this.links.length > 0) {
if (this._contextMenuService) {
this._contextMenuService.show.next({event: event, obj: this.links});
if (this.links && this.links.length > 0) {
if (this._contextMenuService) {
this._contextMenuService.show.next({event: event, obj: this.links});
}
}
}
}