Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable side menu in ionic 4?

I am using, this.menuCtrl.swipeEnable(false); for ionic 3 app. This works fine for disabling the side menu. But, it doesn't work for ionic 4! Below is my ionic 4 code sample:

login.page.ts

constructor(public loginService: LoginService, private router: Router, public menuCtrl: MenuController) {
    this.menuCtrl.swipeEnable(false);
   }

app.component.html

<ion-app>
  <ion-split-pane>
    <ion-menu type="push">
      <ion-header>
        <ion-toolbar color="success">
          <ion-title>Menu</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content>
        <ion-list>
          <ion-menu-toggle auto-hide="false" *ngFor="let p of appPages">
            <ion-item [routerDirection]="'root'" [routerLink]="[p.url]">
              <ion-icon slot="start" [name]="p.icon"></ion-icon>
              <ion-label>
                {{p.title}}
              </ion-label>
            </ion-item>
          </ion-menu-toggle>
        </ion-list>
      </ion-content>
    </ion-menu>
    <ion-router-outlet main></ion-router-outlet>
  </ion-split-pane>
</ion-app>
like image 234
Abhijit Mondal Abhi Avatar asked Aug 11 '18 18:08

Abhijit Mondal Abhi


2 Answers

this.menuCtrl.enable(false);

This will also work in constructor. I am using this in an ionic v4 - beta.2 project and it works fine.

Also, I see that you are using ionic with angular so you can also OnInit lifecycle hook.

like image 198
ashfaq.p Avatar answered Oct 13 '22 12:10

ashfaq.p


Try

this.menuCtrl.enable(false);

This also seems to be answered here disable menu on login page ionic 4

like image 29
Digitizer Avatar answered Oct 13 '22 13:10

Digitizer