app.component.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Component, ViewChild } from '@angular/core';
  2. import { Nav, Platform } from 'ionic-angular';
  3. import { StatusBar } from '@ionic-native/status-bar';
  4. import { SplashScreen } from '@ionic-native/splash-screen';
  5. import { AuthProvider } from '../providers/auth/auth';
  6. import { HomePage } from '../pages/home/home';
  7. import { SearchPage } from '../pages/search/search';
  8. import { SettingsPage } from '../pages/settings/settings';
  9. import { LoginPage } from '../pages/login/login';
  10. @Component({
  11. templateUrl: 'app.html'
  12. })
  13. export class MyApp {
  14. @ViewChild(Nav) nav: Nav;
  15. rootPage: any;
  16. pages: Array<{ title: string, icon: string, component: any }>;
  17. constructor(
  18. platform: Platform,
  19. statusBar: StatusBar,
  20. splashScreen: SplashScreen,
  21. private authProvider: AuthProvider
  22. ) {
  23. platform.ready().then(() => {
  24. // Okay, so the platform is ready and our plugins are available.
  25. // Here you can do any higher level native things you might need.
  26. //this.setHomepage();
  27. statusBar.styleDefault();
  28. splashScreen.hide();
  29. authProvider.isLoggedIn().then(isLoggedIn => {
  30. this.rootPage = isLoggedIn ? HomePage : LoginPage;
  31. })
  32. });
  33. this.pages = [
  34. { title: 'Home', icon: 'home', component: HomePage },
  35. { title: 'Search', icon: 'search', component: SearchPage },
  36. { title: 'Settings', icon: 'settings', component: SettingsPage }
  37. ];
  38. }
  39. openPage(page) {
  40. // Reset the content nav to have just this page
  41. // we wouldn't want the back button to show in this scenario
  42. this.nav.setRoot(page.component);
  43. }
  44. logout() {
  45. this.authProvider.logout();
  46. }
  47. }