Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic2 keeping side menu open

Tags:

angular

ionic2

I'm working with ionic 2, and I have a ion-menu on the left side of the app, which keeps closing when I open the menu and touch to the page area.

I'd like to make it to keep opened and to close only when the user explicitly order to close it(via close button, or maybe swiping back, whatever). is there any option or workaround to doing like that?

EDIT: I started with ionic2-starter-sidemenu. when I run it, it looks like:

---------------------------------------------------------------
|           | <menuToggle button>                             |
|           |-------------------------------------------------|
|           |                                                 |
|           |                                                 |
|     /*    |                                                 |
| side menu |                                                 |
| toggled by|                                                 |
| menuToggle|           /* Content of each Pages */           |
|   button  |                                                 |
|     */    |                                                 |
|           |                                                 |
|           |                                                 |
|           |                                                 |
---------------------------------------------------------------

and when I click the page content area, the menu closes like this:

---------------------------------------------------------------
| <menuToggle button>                                         |
|-------------------------------------------------------------|
|                                                             |
|                                                             |
|                                                             |
|                                                             |
|                /* Content of each Pages */                  |
|                                                             |
|                                                             |
|                                                             |
|                                                             |
|                                                             |
---------------------------------------------------------------

I tried reading documentation and searched ionic forum, but found nothing to resolve it.

like image 225
didrod Avatar asked Dec 12 '16 06:12

didrod


2 Answers

Here is a quick hack until they release an update:

First: Remove menuClose from any of your current side menu buttons

Then in app.component.ts call the MenuController:

constructor(public menuCtrl: MenuController, public platform: Platform) {...

...
initializeApp() {
    this.platform.ready().then(() => {
        this.menuCtrl.open();
    });
}

This does 2 simple behaviors that expose-aside-when did basically:

  • opens the menu when the app is loaded
  • prevents any nav buttons from closing the menu
like image 95
Coldstar Avatar answered Oct 23 '22 02:10

Coldstar


Hope this answer isn't too late. However ionic 2 now supports the splitplane that works exactly as you described. Its syntax is as:

<ion-split-pane>
  <!--  our side menu  -->
  <ion-menu [content]="content">
    <ion-header>
      <ion-toolbar>
        <ion-title>Menu</ion-title>
      </ion-toolbar>
    </ion-header>
  </ion-menu>

  <!-- the main content -->
  <ion-nav [root]="root" main #content></ion-nav>
</ion-split-pane>

enter image description here

like image 41
Isaac Obella Avatar answered Oct 23 '22 03:10

Isaac Obella