Why this.menu.enable(true, 'loggedinMenu') not working in my case

I am building my own app by learning from the ionic conference app"

I am trying like this:
constructor() {
this.menu.enable(true, ‘loggedInMenu’);
But the menu with id “loggedInMenu” isn’t enabled. Sorry that I can’t paste my complete code here. Maybe someone happen to know why it doesn’t work

your menu is declared as in this example? https://github.com/ionic-team/ionic-conference-app/blob/master/src/app/app.template.html

could you check that

My app flow is like this:
app start---->landing page(split page disabled)---->home page(split page enabled again).
I did the same like this on app.component.ts:

   ` // decide which menu items should be hidden by current login status stored in local storage`
   ` this.userData.hasLoggedIn().then((hasLoggedIn) => {`
   ` this.enableMenu(hasLoggedIn === true);`
   `  });`

But it didn’t work. So I tried to troubleshoot like this:

 `this.menu.enable(true, ‘loggedInMenu’);`

And I noticed that, this.menu.enable doesn’t really work:


However, if I wait until the homepage shows and use an event on the homepage to trigger enabling the loggedInMenu on app.component.ts. It works.

I really don’t understand why is like this.

Yes, I did exactly like that. Only I did it indirectly as I described above by using an event, it works.

first, like I said in your other previous post, I would really appreciate if you could format your code, it’s not easy to read like this, sorry to be a bit picky about that

then two things:

  1. could you show the code of your loggedInMenu in your app.component.html?
  2. have you try maybe to add the code in the init block instead of in the constructor?

in your app.component.ts:

ngOnInit() {
<!--<ion-split-pane when="(min-width: 1028px)">//-->
<!-- logged out menu -->

How can I format the whole doc?
I tried this also not working:

ngOnInit() {
console.log("ngOnInit called")
this.menu.enable(true, 'loggedInMenu');
` }

What happens if you try

this.menu.enable(true, ‘loggedInMenu’);
this.menu.enable(false, ‘loggedOutMenu’);


four spaces at the begin of each lines




also not working:

ngOnInit() {
    console.log("ngOnInit called")
   this.menu.enable(true, 'loggedInMenu');
   this.menu.enable(false, 'loggedOutMenu');


thx. :slight_smile: Now I know how to format code. :slight_smile:

1 Like

Mmmmh for me it’s really difficult to answer without having access to the all code I’ve to say

Maybe instead of using the menu in app.component.ts would you like to try in your page?


 ionViewWillEnter() {
    this.menu.enable(true, ‘loggedInMenu’);
    this.menu.enable(false, ‘loggedOutMenu’);

also you could confirm that you don’t see any error in the debugger console right?

Doing it on the pages works!

1 Like

I guess, i need to build a sample plunker to see if I can reproduce the error.
It’s too difficult for you to help me without.
thanks a lot richard.

no worries, it’s just that only the code most of the answer are only guess, but some users of the forum hopefully are better than me to answer questions :wink:

anyway it’s cool if it works in pages

maybe you could follow that pass

Sure. For now, I will do it on pages.
I will find time to reproduce the issue on a sample project.
Thx a lot for your help.

1 Like

Coolio, have fun :slight_smile:

I found out that when I ran:


both returned ‘null’.

the solution:

this.platform.ready().then(() => { })

Many thanks again reedrichards!!

And I hope the solution might help others save lots of time of debugging.

1 Like