ContextMenuService show opens dialog at x:0 y:0
roboter opened this issue · comments
Describe the bug
I am moving away from old package and there dialog is opened in code:
contextMenuService.show.apply(
menu
);
To Reproduce
Steps to reproduce the behavior:
- Button click calls a function
- function tries to open a dialog
- Dialog appear on to of a page
Expected behavior
Should open on where button is
Stackblitz Example
I will prepare it if requested
Hi @roboter, thanks for writing your first issue here.
Some information are missing for me to understand your problem. If you will you can provide, as you suggested, a Stackblitz example.
One thing I can say is that the API slightly changed since the fork depending on which version you have installed. Please read the documentation if you want to open the context menu programmatically https://perfectmemory.github.io/ngx-contextmenu/?path=/story/context-menu-documentation-in-a-nutshell--page#programmatically-open-and-close-a-context-menu
HI
I want to call it from function in component
so I am changing this
ngxContextMenu2.open($event)
to
open2($event, ngxContextMenu)
and in component there are function
open2 = ($event: MouseEvent, anotherMenu: any): void => {
anotherMenu.open($event);
}
From the moment you setup your context menu on any HTML Tag, you can call it anywhere else in the template. The menu will appear wherever your pointer is. Example :
<span
#ngxContextMenu="ngxContextMenu"
[contextMenu]="oneContextMenu"
[contextMenuValue]="value"
tabindex="10"
(click)="ngxContextMenu.open($event)"
(keydown.shift.Y)="ngxContextMenu.open()"
(window:keydown.shift.Z)="ngxContextMenu.close()"
>You can right click on this text</span
>
<button (click)="ngxContextMenu.open($event)"></button>
https://angular-e32noj.stackblitz.io - it does not open on stackbiz and it does not show what error is.
But I wanted to open in Component not in template
In your template you should call open with the right menu reference. Swap ngxContextMenu
with ngxContextMenu1
:
...
#ngxContextMenu1="ngxContextMenu"
(click)="log({$event, ngxContextMenu}); open($event, ngxContextMenu)"
...
to
#ngxContextMenu1="ngxContextMenu"
(click)="log({$event, ngxContextMenu1}); open($event, ngxContextMenu1)"
Hi @roboter,
Did it solved your problem ?
Yes, thank you for help!