Side menu works only for one page


#1

I have added side menu on two pages. None of them are home page. Toggling working for both the pages. But while navigate from one page to other page using side menu, toggling not working for the second page.

Here is my code for side menu for both pages

<ion-menu [content]="content">
        <ion-header>
          <ion-toolbar>
            <ion-title>Menu</ion-title>
          </ion-toolbar>
        </ion-header>
        <ion-content>
          <ion-list>            
            <button ion-item>
              Job Codes
            </button>           
            <button ion-item>
              History
            </button>            
          </ion-list>
        </ion-content>
      </ion-menu>

      <ion-nav id="nav" #content [root]="rootPage"></ion-nav>

<ion-content> 
    <button ion-button menuToggle>Toggle Menu</button>
</ion-content>

#3
<ion-menu [content]="content">
        <ion-header>
          <ion-toolbar>
            <ion-title>Menu</ion-title>
          </ion-toolbar>
        </ion-header>
        <ion-content>
          <ion-list>            
            <button ion-item>
              Job Codes
            </button>           
            <button ion-item>
              History
            </button>            
          </ion-list>
        </ion-content>
      </ion-menu>

now add this to your ts files

  this.pages = [
      { title: 'Job Codes', component: JobCodesPage },
      { title: 'History', component: HistoryPage }
    ];
openPage(page) {
   
    // we wouldn't want the back button to show in this scenario
    this.nav.setRoot(page.component);
  }

That should do the trick


#4

After i remove

<ion-nav id="nav" #content [root]="rootPage"></ion-nav>

from HTML code toggling not working…


#5

Oops please add it. I skipped that


#6

Where is need to add these lines…??
In app.component.ts or to the particular page’s ts…?


#7

Particular ts page in the project


#8

there is a sample sidemenu ionic Project.

ionic start myApp sidemenu

maybe this helps.


#9

But i want to add sidemenu on a existing project. And i don’t need sidemenu on every page.


#10
this.menu.enable(false);

Call this in a page’s contructor to disable menu.

You should still look into the template and copy paste it.
The documentation about menus is kinda weak and confusing.


#11

Yes. But it is very tedious work to recreate a existing project with ionic start myApp sidemenu


#12

Still menu toggling not working in the 2nd page. When i navigate from 1st page using side menu.