PerfectMemory / ngx-contextmenu

A context menu component for Angular

Home Page:https://perfectmemory.github.io/ngx-contextmenu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[help request] Dynamic submenus

baltzarmattsson opened this issue · comments

Hi, thanks for the continued development of the original repo.

I'm trying to achieve this:

image

but with dynamic items instead of a fixed template:

interface MenuItem {
    text: string;
    children?: MenuItem[];
}
const menuItems: MenuItem[] = [
    {
        text: "parent1",
        children: [
            {
                text: "inner1",
                children: [
                    { text: "inner2" }
                ]
            },
        ]
    },
    { text: "no children" }
]

Any idea how I can achieve this? Thanks

Hi @baltzarmattsson,

The documentation for submenus is here https://perfectmemory.github.io/ngx-contextmenu/?path=/docs/context-menu-documentation-in-a-nutshell--docs#sub-menu

It does not include an example with a second level of submenus but it should help you to achieve this.

@baltzarmattsson I also need to do something like you described. I managed to do it after a lot of experimentation and a few hacks.

You can find a working example here: https://github.com/felipecarrillo100/ng-custom-context-menu
Feel free to try it and comment.
I basically created a unique context menu that is reused overall the components in the application. The components interact with the component using a service that allows them to open menus with new options. Have a look

@felipecarrillo100 Amazing, thank you!

I am closing this issue considering by your last comment you found a solution. Please comment if this is not the case.