2

I am trying to create dynamic, nested menus in Angular(9), following this link.

I don't know what is missing, getting below errors.

enter image description here

enter image description here

My code in stackblitz. TIA.

3
  • 1
    what you trying do here can explain more Commented May 6, 2020 at 10:33
  • @harkeshkumar I am trying to create dynamic menus using mentioned link, but unable to create.. Commented May 6, 2020 at 10:55
  • @RazRonen can you please explain more, not getting you. Commented May 6, 2020 at 10:55

1 Answer 1

4

The issue here is that menu.childMenu, which is ViewChild, is not initalized yet at the time of passing it to the matMenuTriggerFor directive.

Simple fix is to tell Angular to initialize it before ngOnInit by using static: true option in @ViewChild decorator:

@ViewChild('childMenu', { static: true }) public childMenu;

Forked Stackblitz

Sign up to request clarification or add additional context in comments.

1 Comment

thanks @yurzui, its working like a charm on stackblitz. Actually I have already tried it but had no luck. Wasted lots of time on this fix, thanks alot again. Just checking if its working in project as well, will let you know...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.