Code: Select all
<p-tree [value]="treeItems" selectionMode="single" [(selection)]="selectedItem" [contextMenu]="treeContextMenu"></p-tree>
<p-contextMenu #treeContextMenu [model]="menuItems"></p-contextMenu>
I've tried binding the `contextMenu` property to a method that returns the `ContextMenu` reference and run the logic there, but it didn't work. Something like:
Code: Select all
<p-tree [value]="treeItems" selectionMode="single" [(selection)]="selectedItem" [contextMenu]="buildContextMenu()"></p-tree>
<p-contextMenu #treeContextMenu [model]="menuItems"></p-contextMenu>
// IN THE COMPONENT CODE:
@ViewChild('treeContextMenu') treeContextMenu: ContextMenu;
public buildContextMenu(): ContextMenu {
// NOTE: getItemMenuOptions is a method that return the appropriate items to show for the selected item in the tree
const menuItemsToShow = this.getItemMenuOptions();
// Update the context menu items (so it'll be updated in the 'treeContextMenu' component)
this.menuItems = menuItemsToShow;
// Return the reference to the context menu
return this.treeContextMenu;
}
Thanks in advance,