如何从打字稿访问 mat 菜单触发器 [英] How do I access mat menu trigger from typescript
本文介绍了如何从打字稿访问 mat 菜单触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 html:
<button mat-icon-button #notificationMenuBtn [matMenuTriggerFor]="notificationsMenu">
</button>
<mat-menu #notificationsMenu="matMenu" [overlapTrigger]="false">
</mat-menu>
如何从打字稿访问notificaitonMenuBtn 上的thematMenuTriggerFor?我尝试使用 View Child(如下所示),但似乎无法将其绑定到触发器,只能绑定到按钮.
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();
推荐答案
想通了.我只需要使用 MatMenuTrigger 而不是元素 id.
Figured it out. I just needed to use MatMenuTrigger instead of the element id.
@ViewChild(MatMenuTrigger) notificationMenuBtn: MatMenuTrigger;
这篇关于如何从打字稿访问 mat 菜单触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文