how to active side menu in ionic3

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, AlertController, MenuController, Icon }
from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { HomePage } from '../pages/home/home';
import { WelcomePage } from '../pages/welcome/welcome';
import { Storage } from '@ionic/storage';
import { NetworkInterface } from '@ionic-native/network-interface';
import { Network } from '@ionic-native/network';
import { ChangepasswordPage } from '../pages/changepassword/changepassword';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;

rootPage: any;

pages: Array<{title: string,icon: string, component: any}>;
closelogin: boolean;
user: string;
username: string;
activepage: any;

constructor(public platform: Platform,
public network: Network,
private networkInterface: NetworkInterface,
public menu: MenuController,
public alertController: AlertController,
public statusBar: StatusBar,
public storage: Storage,
public splashScreen: SplashScreen) {
this.initializeApp();

// used for an example of ngFor and navigation
this.pages = [
{ title: 'Home',icon:'ios-home', component: HomePage },
{ title: 'Change Password', icon:'ios-create', component: "ChangepasswordPage" }
];
this.activepage= this.pages[0];
}

initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.user=localStorage.getItem("loginfieldstaffpramann");
if(this.user=='"YES"')
{
this.rootPage=HomePage;}
else
{
this.rootPage="WelcomePage";
}
this.splashScreen.hide();

});
}

openPage(page) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
this.activepage= page;
this.menu.close();
}
ngOnInit() {
if (localStorage.getItem("loginfieldstaffpramann") == '"YES"') {
debugger;
this.closelogin = false;
}
}
checkNewUserActive(page) {
this.username = "FieldStaff";
return page == this.activepage;
}
logout() {
this.menu.swipeEnable(false);
let alert = this.alertController.create({
title: 'Logout?',
message: 'Are you sure you want to logout?',
buttons: [{
text: 'No'
}, {
text: 'Yes',
handler: () => {
this.storage.clear();
localStorage.setItem("loginfieldstaffpramann", JSON.stringify("NO"));
this.nav.setRoot("WelcomePage");
window.location.reload();
}
}]
});
alert.present();
}
}


<div *ngIf="!closelogin">
<ion-menu [content]="content" side="left" id="field_staff_menu" >

<ion-header>
<ion-toolbar color="pramaan">
<img class="menu-user-image" src="assets/imgs/logo_big.png">
<div class="font18" text-center>Welcome {{username}}</div>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list no-lines>
<button [class.activeHighlight] ="checkNewUserActive(p)"
ion-item *ngFor="let p of pages" (click)="openPage(p)">
<ion-icon name="{{p.icon}}" width="30"></ion-icon>
{{p.title}}
</button>
<button ion-item (click)="logout()">
<ion-icon name="ios-log-out-outline"></ion-icon>
Logout
</button>
</ion-list>
</ion-content>

</ion-menu>
</div>


<ion-nav [root]="rootPage" #content></ion-nav>


.activeHighlight{
color: #357CA5;
font-weight: 500 !important;

Comments

Popular posts from this blog

Your app currently targets API level 27 and must target at least API level 28 to ensure it is built on the latest APIs optimized for security and performance. Change your app's target API level to at least 28

ionic project creation

change root user in ubuntu