Ionic toggle menu doesn't close side menu on android device

Viewed 4167

I have an Ionic 4 project and I'm using a side menu. There's a menu button that opens the menu, and in the menu is a list of menu-choices, when selected the menu-choice closes the side menu. This works in a browser, but not on a device. The menu will open, but not close.

My side menu is in my app.component.html

<ion-app>
  <ion-menu side="start" type="push" contentId="content1">
      <ion-header>
        <ion-toolbar color="primary">
          <ion-title>Menu</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content class="light-grey">
        <ion-list>
          <ion-item (click)="toggleMenu()" [routerLink]="['/home']" routerLinkActive="active-link">Home</ion-item>
          <ion-item (click)="toggleMenu()" [routerLink]="['/dashboard']" routerLinkActive="active-link">Dashboard</ion-item>
        </ion-list>
      </ion-content>
    </ion-menu>
    <ion-router-outlet id="content1" main></ion-router-outlet>
</ion-app>

Here is a sample of the homepage

<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-menu-button autoHide="false" menuToggle></ion-menu-button>
          </ion-buttons>
        <ion-title>
         Opportunity Forms
        </ion-title>
    </ion-toolbar>
  </ion-header>

<ion-content>
  <ion-refresher slot="fixed"  (ionRefresh)="ionRefresh($event)" >
      <ion-refresher-content 
          pulling-icon="arrow-dropdown"
          pulling-text="Pull to refresh"
          refreshing-spinner="circles"
          refreshing-text="Refreshing...">
      </ion-refresher-content>
    </ion-refresher>
  <ion-card> 
      <ion-card-content>


      </ion-card-content>
    </ion-card>
</ion-content>

Here is a screenshot of the app

enter image description here

Works in Chrome Version 77.0.3865.90 Tested and menu does not close on Android 9

Any help is appreciated, hopefully I've provided enough information.

-- Edit (adding app.component.ts) --

import { Component } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import {MenuController} from '@ionic/angular';
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private menu: MenuController,
    private route: Router
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }
  toggleMenu() {
    this.menu.toggle(); //Add this method to your button click function
  }
}
3 Answers

Please see this. It discusses the issue: https://github.com/ionic-team/ionic/issues/19354

They suggest updating @ionic/angular to 4.11.2. That did not work for everyone but another proposed solution that worked for someone is:

<ion-menu-toggle menu="first" autoHide="false">

Please give the following code a try:

<ion-app>
    <ion-menu side="start" type="push" contentId="content1">
        <ion-header>
          <ion-toolbar color="primary">
            <ion-title>Menu</ion-title>
          </ion-toolbar>
        </ion-header>
        <ion-content class="light-grey">
          <ion-list>
            <ion-item (click)="toggleMenu()" [routerLink]="['/home']" routerLinkActive="active-link">Home</ion-item>
            <ion-item (click)="toggleMenu()" [routerLink]="['/dashboard']" routerLinkActive="active-link">Dashboard</ion-item>
          </ion-list>
        </ion-content>
      </ion-menu>
      <ion-router-outlet id="content1" main></ion-router-outlet>
</ion-app>

You have mixed two possible ways. One way is to add ion-menu-toggle in html. Another way is to add a toggle method in app.component.ts and to add a click event in the app.component.html. You have already added the toggle method in die app.component.ts, but you don't have added a click event on the items in the app.component.html..

you need to import MenuController and then use that in the button:

the typescript:

...
import { ToastController } from '@ionic/angular';

@Component({
  selector: 'app-menu',
  templateUrl: './menu.component.html',
  styleUrls: ['./menu.component.scss'],
})
export class MenuComponent implements OnInit {
  constructor(
    public menu: MenuController
  ) {}
}

the html:

<ion-menu side="end" menuId="first" contentId="main">
  <ion-content>
    <ion-list>
      <ion-item button (click)="this.menu.close()" routerLink="/home">
        <ion-icon name="home-outline" color="primary"></ion-icon>
        Home
      </ion-item>
      <ion-item button (click)="this.menu.close()" routerLink="/my-profile">
        <ion-icon name="person-circle-outline" color="primary"></ion-icon>
        My Profile
      </ion-item>
    </ion-list>
  </ion-content>
</ion-menu>
Related