Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 4 adding side menu

i started a project with tab template which i then later decided to add a side menu. the trouble is the side menu does not appear at all. here is my app.components.html looks like

<ion-app>
    <ion-split-pane>
        <ion-menu side="start">
            <ion-header translucent>
              <ion-toolbar color="secondary">
                <ion-title>Menu</ion-title>
              </ion-toolbar>
            </ion-header>
            <ion-content><ion-list><ion-item>he vik</ion-item></ion-list></ion-content>
          </ion-menu>
          <ion-router-outlet></ion-router-outlet>

        </ion-split-pane>
</ion-app>

actually after doing above my actual page comes for a brief second and shows a white page due to this.

in the console i see an error

sz7tok82.entry.js:5 Menu: must have a "content" element to listen for drag events on.

but i already have content element.

like image 297
Vik Avatar asked Dec 06 '18 18:12

Vik


People also ask

How do I add side menus in Ionic 4?

In the page you want to show your side menu, you can use the ion-menu-button tag. Set the autoHide tag to false, so you will always see the menu button.


2 Answers

Sirius2013 is correct, you will need to use the contentId attribute. See a working example below:

App.component.html

<ion-app>
  <ion-menu contentId="content1" side="start">
    <ion-header>
      <ion-toolbar>
        <ion-title>Menu</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content>
      menu stuff
    </ion-content>
  </ion-menu>
  <ion-router-outlet id="content1" main></ion-router-outlet>
</ion-app>


AnyPage.html

In the page you want to show your side menu, you can use the ion-menu-button tag.
See this example:

<ion-header>
  <ion-toolbar>
    <ion-title>Page Title</ion-title>
    <ion-buttons slot="start">
      <ion-menu-button autoHide="false"></ion-menu-button>
    </ion-buttons>
  </ion-toolbar>
</ion-header>

Set the autoHide tag to false, so you will always see the menu button.

Docs: https://beta.ionicframework.com/docs/api/menu-button

like image 52
Tomas Vancoillie Avatar answered Oct 01 '22 22:10

Tomas Vancoillie


<ion-menu>
  <ion-header>
    <ion-toolbar>
      <ion-title>Menu</ion-title>
    </ion-toolbar>
  </ion-header>
</ion-menu>
<ion-router-outlet main></ion-router-outlet>

https://beta.ionicframework.com/docs/api/menu

Try to use contentId attribute.

like image 42
sirius2013 Avatar answered Oct 01 '22 21:10

sirius2013