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.


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>
Take a look at @ViewChild. Note the opts/read parameters for when your queries get more complicated.
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._
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