[SOLVED] Menu.enable() not working on page load for multiple menus on same side


#1

Hi, i was following the conference app examples for the multiple menus on same side, everything works fine until i reload, when i reload the app, it sets the default menu.

in the app.ts’s constructor i have this code, like in the conference app to check login state and enabling one menu or the other depending:

this.localStorageProvider.checkLoginState().then((loggedIn) => {
      
      this.enableMenu(loggedIn === 'true');
           
    }).catch(error => {
      console.error(error);
    });

and then in the enableMenu i have:

enableMenu(loggedIn){
    console.log('Current loggedIn: '+ loggedIn);
    this.menu.enable(loggedIn, 'logged-in-menu');
    this.menu.enable(!loggedIn, 'logged-out-menu');
  }

the enable menu only works after the page is loaded and an event is triggered, but when i reload the app, it sets the default menu again, i tried triggering an event on from the constructor, but got the same result.

need help here!

PD: I just cloned the conference app and its doing the same thing! menu.enable not working on app reload.

UPDATE: I solved it by setting a timeout of 500 ms on the constructor like this:

this.localStorageProvider.checkLoginState().then((loggedIn) => {
    setTimeout(() => {
                  this.enableMenu(loggedIn === 'true');
                }, 500);
}).catch(error => {
          console.error(error);
        });

i guess this is being looked into right?


#2
Home Cats Home2 Cats2

I have a testbed side menu (the above with a button stripped out for readibility), and
the enabled= on ion-menu correctly controls which menu to display.

However, when I attempt to do so in the constructor (after stripping out the 2 enabled= above)
with:
let showMenu:boolean = true;
this.menu.enable(showMenu, ‘mnuOne’)
this.menu.enable(!showMenu, ‘mnuTwo’)
only mnuOne displays, regardless of the value of showMenu.

however, it works when I place it in a timeout


per August 2016.
setTimeout(() => {
let showMenu:boolean = true;
this.menu.enable(showMenu,“mnuOne”);
this.menu.enable(!showMenu,“mnuTwo”);
}, 500);

ionic 3.17.0