title: Angular 5 Material Multiple mat-menu
body: <p>I am quite new to Angular 5 and have just started learning it.<br/><br />
  Recently, I have been trying to create a menu bar with multiple menus for my app using Angular 5 Material.<br />
  The menu will be triggered/opened during mouse enter and closed when the mouse leaves the menu.<br />
  My problem is that everytime the mouse mouse hovers to the first menu it loads the menu items of the 2nd menu. <br /><br />Here is a screenshot of the problem:<br />
  <a href="https://i.stack.imgur.com/0V4iM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0V4iM.png" alt="enter image description here"></a>
  <br /><br />
  Here are my codes: <br />
  <strong>mainmenu.component.html</strong>: <br /></p>
  
  <pre><code>&lt;div&gt;
      &lt;button mat-button [matMenuTriggerFor]="menu1" 
        (mouseenter)="openMyMenu()"&gt;Trigger1&lt;/button&gt;
      &lt;mat-menu #menu1="matMenu" overlapTrigger="false"&gt;
          &lt;span (mouseleave)="closeMyMenu()"&gt;
              &lt;button mat-menu-item&gt;Item 1&lt;/button&gt;
              &lt;button mat-menu-item&gt;Item 2&lt;/button&gt;
          &lt;/span&gt;
     &lt;/mat-menu&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;button mat-button [matMenuTriggerFor]="menu2"
        (mouseenter)="openMyMenu()"&gt;Trigger2&lt;/button&gt;
      &lt;mat-menu #menu2="matMenu" overlapTrigger="false"&gt;
          &lt;span (mouseleave)="closeMyMenu()"&gt;
              &lt;button mat-menu-item&gt;Item 3&lt;/button&gt;
              &lt;button mat-menu-item&gt;Item 4&lt;/button&gt;
          &lt;/span&gt;
      &lt;/mat-menu&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><br /><br />
  <strong>mainmenu.component.ts</strong>:<br /></p>
  
  <pre><code>import { Component, OnInit, ViewChild } from '@angular/core';
  import {MatMenuTrigger} from '@angular/material'
  
  @Component({
    selector: 'app-mainmenu',
    templateUrl: './mainmenu.component.html',
    styleUrls: ['./mainmenu.component.css']
  })
  export class MainmenuComponent implements OnInit {
    @ViewChild(MatMenuTrigger) matMenuTrigger: MatMenuTrigger;
  
    constructor() { }
  
    ngOnInit() {
    }
    openMyMenu() {
      this.matMenuTrigger.openMenu();
  
    } 
    closeMyMenu() {
      this.matMenuTrigger.closeMenu();
    }
  }
  </code></pre>
  
  <p>I also tried this: <code>@ViewChild('menu1') matMenuTrigger: MatMenuTrigger;</code>
  but I am getting errors.
  <br />
  Your opinions and advices are very much appreciated!
  <br />
  <br />
  <br />
  Thanks,<br />
  Artanis Zeratul
  <br />
  <br />
  References:</p>
  
  <ul>
  <li><a href="https://coursetro.com/posts/code/113/How-to-Build-an-Angular-5-Material-App" rel="noreferrer">https://coursetro.com/posts/code/113/How-to-Build-an-Angular-5-Material-App</a></li>
  <li><a href="https://stackoverflow.com/questions/47695998/how-to-make-material-design-menu-mat-menu-hide-on-mouseleave">How to make Material Design Menu (mat-menu) hide on mouseleave</a></li>
  </ul>
  
  <p><br /></p>