Mig*_*ger 4 typescript material-design angular
我有以下html:
<button mat-icon-button #notificationMenuBtn [matMenuTriggerFor]="notificationsMenu">
</button>
<mat-menu #notificationsMenu="matMenu" [overlapTrigger]="false">
</mat-menu>
Run Code Online (Sandbox Code Playgroud)
如何从typescript上访问notificaitonMenuBtn上的thematMenuTriggerFor?我尝试使用View Child(如下所示),但我似乎无法将其绑定到触发器,仅绑定到按钮.
@ViewChild('notificationMenuBtn') notificationMenuBtn : MatMenuTrigger;
this.notificationMenuBtn.openMenu();
Run Code Online (Sandbox Code Playgroud)
小智 10
如果你真的需要使用id(当你有几个MatMenuTrigger时)
@ViewChild('notificationMenuBtn', {read: MatMenuTrigger}) protected notificationMenuBtn : MatMenuTrigger;
Run Code Online (Sandbox Code Playgroud)
弄清楚了.我只需要使用MatMenuTrigger而不是元素id.
@ViewChild(MatMenuTrigger) notificationMenuBtn: MatMenuTrigger;
Run Code Online (Sandbox Code Playgroud)