PerfectMemory / ngx-contextmenu

A context menu component for Angular
https://perfectmemory.github.io/ngx-contextmenu
MIT License
42 stars 12 forks source link

[help request] Dynamic submenus #27

Closed baltzarmattsson closed 1 year ago

baltzarmattsson commented 1 year ago

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

sroucheray commented 1 year ago

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.

felipecarrillo100 commented 1 year ago

@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

baltzarmattsson commented 1 year ago

@felipecarrillo100 Amazing, thank you!

sroucheray commented 1 year ago

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