isaacplmann / ngx-contextmenu

An Angular component to show a context menu on an arbitrary component
MIT License
248 stars 91 forks source link

On open Context menu first time hidden menu items are shown #137

Open Navyasri-Gurram opened 6 years ago

Navyasri-Gurram commented 6 years ago

Here is my code, am trying to hide ng-template dynamically when context menu is opened. But for the first time when i open context menu, menu item is not hidden. Second time when i open again on right click then menu item hidden.

I need to hide my menu item each time when i open context menu.

     <context-menu>
        <ng-template contextMenuItem (execute)="clickMe($event.item)">
         Add Login
        </ng-template>
        <ng-template contextMenuItem (execute)="CheclickHidden($event.item)"                  [visible]="hidenMe">
        delete Login
         </ng-template>
      </context-menu>

      public onContextMenu($event: MouseEvent, item: any, index): void {

      this.hidenMe=false;
          this.contextMenuService.show.next({
          event: $event,
           item: { item, index },
      });

     $event.preventDefault();
     $event.stopPropagation();
   }
isaacplmann commented 6 years ago

I think there are important parts of your code that I'm missing, but this could work for you:

this.hidenMe=false;
setTimeout(() => {
  this.contextMenuService.show.next({
    event: $event,
    item: { item, index },
  });
});