Created
June 8, 2018 12:46
-
-
Save adash333/203954692d24cd28b5219d97faa26d96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 page components and authentication provider | |
import { HomePage } from '../pages/home/home'; | |
import { ListPage } from '../pages/list/list'; | |
import { LoginPage } from '../pages/login/login'; | |
import { AuthProvider } from '../providers/auth/auth'; | |
@Component({ | |
templateUrl: 'app.html' | |
}) | |
export class MyApp { | |
@ViewChild(Nav) nav: Nav; | |
/** | |
* Set the root page for the application | |
*/ | |
public rootPage: any = LoginPage; | |
/** | |
* Define the pages for the application | |
*/ | |
private pages: Array<{title: string, component: any}>; | |
constructor( | |
public platform: Platform, | |
public statusBar: StatusBar, | |
public splashScreen: SplashScreen, | |
private _AUTH: AuthProvider | |
) { | |
this.initializeApp(); | |
// Populate pages for the application | |
this.pages = [ | |
{ title: 'Home', component: HomePage }, | |
{ title: 'List', component: ListPage }, | |
{ title: 'Logout', component: LoginPage} | |
]; | |
} | |
/** | |
* Initialise the application | |
* @method initializeApp | |
* return { none } | |
*/ | |
initializeApp(): void { | |
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(); | |
}); | |
} | |
/** | |
* Open a page from the sidemenu | |
* @method openPage | |
* @param page { object } | |
* return { none } | |
*/ | |
openPage(page: any): void { | |
// Ensure we can log out of Firebase and reset the root page | |
if(page == 'LogOut') { | |
this._AUTH.logOut().then((data: any) => { | |
this.nav.setRoot(page.component); | |
}).catch((error: any) => { | |
console.dir(error); | |
}); | |
} | |
// Otherwise reset the content nav to have just this page | |
// we wouldn't want the back button to show in this scenario | |
else { | |
this.nav.setRoot(page.component); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment