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’);
console.log(this.menu)
}
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);`
   `  });`
  `this.enableMenu(true);`

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

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

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

 `enabled:false`
 `id:"loggedInMenu"`

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() {
   this.enableMenu(true);
}
<!--<ion-split-pane when="(min-width: 1028px)">//-->
<ion-split-pane>
<!-- 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');
console.log(this.menu)
` }

What happens if you try

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

?

four spaces at the begin of each lines

____something

=>

something

also not working:

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

}

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?

Like

 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:

this.menu.get('loggedInMenu')
this.menu.get('loggedOutMenu')

both returned ‘null’.

the solution:

this.platform.ready().then(() => { })
  this.enableMenu(this.auth.hasLoggedIn());
});

Many thanks again reedrichards!!

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

1 Like