Components: [Question]: MdMenuTrigger - how to utilize API methods

Created on 25 Jul 2017  路  3Comments  路  Source: angular/components

Sorry to ask this here, but I don't know where else to ask it.

It's not clear to me from the docs on how I can use the API methods listed for components/directives. In this case I'm wanting to open and close a menu programmatically using the "openMenu" and "closeMenu" methods respectively.

image
image

I've tried importing and creating an instance within my component (not sure how to satisfy the constructor arguments) as well as passing the trigger element to a class function (provides instance of md-button and not md-menu-trigger).

import { MdMenuTrigger } from '@angular/material';

// class definition ...
constructor() {
    this.shipItMenuTrigger = new MdMenuTrigger();
  }

openMenu(menu:MdMenuTrigger) {
    //console.log(menu);
    //console.log(menu.openMenu);
    console.log(this.shipItMenuTrigger.openMenu);
  }


<button #shipItMenuTrigger
               md-button
               [mdMenuTriggerFor]="shipItMenu"
               (mouseenter)="openMenu(shipItMenuTrigger)">Ship It
</button>

Most helpful comment

Take a look at @ViewChild. Note the opts/read parameters for when your queries get more complicated.

https://plnkr.co/edit/O2FJgunnKfJi4MfFb0E6?p=preview

All 3 comments

Take a look at @ViewChild. Note the opts/read parameters for when your queries get more complicated.

https://plnkr.co/edit/O2FJgunnKfJi4MfFb0E6?p=preview

Thanks for such a clear and straightforward example. That helps me understand it a lot better.

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._

Was this page helpful?
0 / 5 - 0 ratings