import { Component, ViewChild } from '@angular/core'; import { Nav, Platform } from 'ionic-angular'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; import { AppInit } from '../providers/app-init/app-init'; import { LoginSvc } from '../providers/login/login.service'; import { AppConf } from '../providers/app-conf/app-conf'; @Component({ templateUrl: 'app.html' }) export class MyApp { @ViewChild(Nav) nav: Nav; rootPage: any = 'LoginPage'; pages: Array<{ title: string, component: any }>; constructor(public appInit: AppInit, public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public loginSvc: LoginSvc, public appConf: AppConf) { this.initializeApp(); // used for an example of ngFor and navigation this.pages = [ { title: 'Home', component: 'HomePage' }, { title: 'SyncManager', component: 'SyncManagerPage' }, { title: 'Setting', component: 'SettingPage' }, ]; } 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.splashScreen.hide(); this.appInit.init(); if (this.appConf.isLogin() === true) { // check if user already login // $state.go('application.home') this.rootPage='HomePage'; } }); } 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); } logout() { this.loginSvc.logout(); this.nav.setRoot('LoginPage'); } }