Pablo Taiocchi
Pablo Taiocchi

Reputation: 33

How close menu from ionic 5

I have a simple question but I cant't find a solution. I created a new project in Ionic 5 and I use "sidemenu" template. From documentation I read that close method should close the menu. I put in the constructor "public menuCtrl: MenuController" and in ngOnInit:

this.menuCtrl.close();

but nothing works. From debug I see menuCtrl empty.... Any ideas?

Upvotes: 3

Views: 1894

Answers (1)

rtpHarry
rtpHarry

Reputation: 13125

The MenuController is in your top level app.component page not in the individual page so you would need to write the code inside app.component.ts.

Alternatively you can automate it by wrapping each menu item in a ion-menu-toggle like:

  <ion-list>
    <ion-menu-toggle auto-hide="true" *ngFor="let page of navigate">
      <ion-item [routerLink]="page.url" routerDirection="forward">
        <ion-icon [name]="page.icon" slot="start"></ion-icon>
        {{ page.title }}
      </ion-item>
    </ion-menu-toggle>
  </ion-list>

Upvotes: 2

Related Questions