I have the following html:
<button mat-icon-button #notificationMenuBtn [matMenuTriggerFor]="notificationsMenu">
</button>
<mat-menu #notificationsMenu="matMenu" [overlapTrigger]="false">
</mat-menu>
How to I access thematMenuTriggerFor on the notificaitonMenuBtn from typescript? I tried using a View Child (shown below) but I can't seem to bind it to the trigger, only to the button.
@ViewChild('notificationMenuBtn') notificationMenuBtn : MatMenuTrigger;
this.notificationMenuBtn.openMenu();
If you really need to use an id (When you have several MatMenuTrigger)
@ViewChild('notificationMenuBtn', {read: MatMenuTrigger}) protected notificationMenuBtn : MatMenuTrigger;
Figured it out. I just needed to use MatMenuTrigger instead of the element id.
@ViewChild(MatMenuTrigger) notificationMenuBtn: MatMenuTrigger;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With