components icon indicating copy to clipboard operation
components copied to clipboard

How to open a particular menu programmatically if more than one menu element?

Open vkishorekumar80 opened this issue 9 years ago • 10 comments

If I have more than one menu element in a page, how will I open a particular menu based on the context or how can I select a menu element using ViewChild by specifying the name?

Plunker: https://plnkr.co/edit/iVgoBU?p=preview

vkishorekumar80 avatar Dec 27 '16 12:12 vkishorekumar80

@crisbeto What could be done for this kind of scenario?

vkishorekumar80 avatar Dec 30 '16 20:12 vkishorekumar80

I couldn't got your question, what would you like to achieve?

EladBezalel avatar Jan 12 '17 11:01 EladBezalel

https://plnkr.co/edit/gbpvuno5thiUzlYNIcb3?p=preview In the example, how will I open the second menu when I click on the "open second menu button"?.

vkishorekumar80 avatar Jan 12 '17 11:01 vkishorekumar80

So you can do something like that: https://plnkr.co/edit/ScrbSJQWkAdjaAI7EKQU?p=preview The better approach would be using a query selector

  @ViewChild('trial') trigger: MdMenuTrigger;

But i'm getting the mdButton directive instead of the trigger, i will check what we can do with that.

EladBezalel avatar Jan 12 '17 12:01 EladBezalel

Thanks @EladBezalel . Will wait for the update. I got the same result when I tried with the first plnkr sample. At times we cannot rely on the index and need to find out the controls by name.

vkishorekumar80 avatar Jan 12 '17 12:01 vkishorekumar80

Take a look here: https://plnkr.co/edit/AmWcuUNw1YaZeluLq0aJ?p=preview

EladBezalel avatar Jan 12 '17 14:01 EladBezalel

Perfect. @EladBezalel Thanks for the help.

vkishorekumar80 avatar Jan 12 '17 14:01 vkishorekumar80

How do we assign mdMenuTriggerFor dynamically ?

[mdMenuTriggerFor]="link.menuName"

shijithkm avatar Apr 21 '17 08:04 shijithkm

@shijithkm You can see here https://stackblitz.com/edit/dynamic-nested-menus?file=app%2Fapp.component.ts

SergeyKurdyukov avatar Feb 15 '19 08:02 SergeyKurdyukov

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.