Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access mat menu trigger from typescript

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();
like image 831
MightyMorphingAndroidRanger Avatar asked Nov 02 '17 16:11

MightyMorphingAndroidRanger


2 Answers

If you really need to use an id (When you have several MatMenuTrigger)

@ViewChild('notificationMenuBtn', {read: MatMenuTrigger}) protected notificationMenuBtn : MatMenuTrigger;
like image 73
jpierront Avatar answered Nov 12 '22 07:11

jpierront


Figured it out. I just needed to use MatMenuTrigger instead of the element id.

@ViewChild(MatMenuTrigger) notificationMenuBtn: MatMenuTrigger;
like image 40
MightyMorphingAndroidRanger Avatar answered Nov 12 '22 07:11

MightyMorphingAndroidRanger