简体   繁体   中英

How to hide sidemenu after logout in ionic 2

I created login and logout functionality I given logout in side menu. Logout functionality working properly but the problem after logout side menu is seeing. How to hide side menu after logout and go home page.

在此处输入图像描述

You can use the menuClose directive :

The menuClose directive can be placed on any button to close an open menu.

A simple menuClose button can be added using the following markup:

<button ion-button menuClose>Close Menu</button>

or

<button ion-item menuClose>Close Menu</button>

That would make the menu to be closed when you select the logout option from the side menu.


If you want to have more control over the menu, you can use the MenuController and use it to close the menu programmatically, from the component code.

import { Component } from '@angular/core';
import { MenuController } from 'ionic-angular';

@Component({...})
export class MyPage {

 constructor(public menuCtrl: MenuController) {

 }

 openMenu() {
   this.menuCtrl.open();
 }

 closeMenu() {
   this.menuCtrl.close();
 }

 toggleMenu() {
   this.menuCtrl.toggle();
 }

}
import { MenuController } from '@ionic/angular';

constructor(public menuCtrl: MenuController)

logout(){
    this.menuCtrl.close();
    this.router.navigate(['home']);

}

Latest Ionic version code may be used like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM