Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested navigation menu with CdkMenu

I struggle to make a full working navigation with nested menus using the @angular/cdk menu module.

Here is the StackBlitz.

Why are the nested menus not closing when I select another top-level menu?

The example we have:

| menu 1 | menu 2 |

When we click on menu 1, its submenu is displayed; and when I click on menu 2, the submenu of menu 1 does not close automatically and stays open. (see StackBlitz)

like image 866
Pain Avatar asked Jun 23 '26 19:06

Pain


1 Answers

Apply { static: true } in @ViewChild should resolve the issue:

@ViewChild('childMenu', { static: true }) public childMenu!: TemplateRef<any>;

Demo @ StackBlitz

like image 159
Yong Shun Avatar answered Jun 26 '26 04:06

Yong Shun