Issue
I want my material menu to open automatically when my page is opened, but because I am not click, "trigger" is undefined
TypeError: Cannot read properties of undefined (reading 'openMenu')
@ViewChild('menuTrigger') trigger;
ngOnInit() {
if (this.headerService.isCookieDown = "0") {
this.trigger.openMenu()
}
}
<button mat-button #menuTrigger="matMenuTrigger" [matMenuTriggerFor]="infomenu"><img bell.svg"></button>
<mat-menu class="info-menu" style="max-width: 400px !important;" [hasBackdrop]="false" #infomenu="matMenu">
html codes..
</mat-menu>
Solution
Implement the ngAfterViewInit lifecycle hook and make the openMenu
call in ngAfterViewInit
, like below.
ngAfterViewInit() {
if (this.headerService.isCookieDown = "0") {
this.trigger.openMenu()
}
}
Answered By - R. Richards
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.