Hide Primeng context menu with a condition

Viewed 2229

I'm trying to hide the context menu when there is a condition applied. I've come across this post and followed through with it but still, the context menu is showing. I'm trying to add context menu to p-table and I have a condition where if there are no options available then I want to hide context menu but when I'm calling hide() method on context menu it's not working. below are the code snippets of what I did so far.

In .html file

<p-table #table (onContextMenuSelect)="onContextMenuSelect($event, tableContextMenu)" [contextMenu]="tableContextMenu"> </p-table>
<p-contextMenu #tableContextMenu appendTo="body" [model]="contextMenus"></p-contextMenu>

In .ts file

 public onContextMenuSelect(event, contextMenu){
     if(this.loadContextMenu){
     contextMenu.hide();
   }
}
1 Answers

Changing (onContextMenuSelect) to contextmenu will trigger contextMenu.hide(); if condition is matched.

<p-table #table (contextmenu)="onContextMenuSelect($event, tableContextMenu)" [contextMenu]="tableContextMenu"> </p-table>

Related