2016-06-15 2 views
3

私はユーザーがログインしているかどうかに応じてルートページを設定しようとしています。アプリは、私が望むページに移動しません。しかし、私が別のページに変更すると、それは動作します。だから私は、私がナビゲートしているページで何かが間違っているはずだと思ったが、私はそれを理解していないようだ。イオン2ベータ8のルートページは移動しないでください

app.ts:

import {Component, ViewChild} from '@angular/core'; 
import {Platform, ionicBootstrap, Nav} from 'ionic-angular'; 
import {StatusBar} from 'ionic-native'; 
import {TabsPage} from './pages/tabs/tabs'; 
import {StartPage} from './pages/startPage/startPage'; 
import {LoadingScreen} from './pages/loadingScreen/loadingScreen'; 
import {AuthService} from './services/AuthService'; 

@Component({ 
    template: '<ion-nav id="nav" [root]="rootPage"></ion-nav>', 
    queries: { 
    nav: new ViewChild('content') 
    } 
}) 

export class MyApp { 

    @ViewChild(Nav) nav: Nav; 
    rootPage: any; 

    constructor(platform: Platform, private auth: AuthService) { 

    this.rootPage = LoadingScreen; 

    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. 
     StatusBar.styleDefault(); 
    this.initialize(); 
    }); 


    } 

    initialize() { 

     this.auth.loggedIn().then(isLoggedIn => { 

      console.log(isLoggedIn); 
      if (isLoggedIn) { 

       //This works 
       this.nav.setRoot(TabsPage); 

      } else { 

       //This doesn't work, but if I change the page to TabsPage it works 
       this.nav.setRoot(StartPage); 

      } 

     }); 

    } 
} 

ionicBootstrap(MyApp, [AuthService], { 
    backButtonText: 'Back' 
}) 

StartPage.ts:

import {Component} from '@angular/core'; 
import {NavController} from 'ionic-angular'; 
import {LoginPage}from '../loginPage/loginPage'; 

@Component({ 
    templateUrl: 'build/pages/startPage/startPage.html' 
}) 

export class StartPage { 


    constructor(private nav: NavController) { 

    } 

    login(){ 

    this.nav.push(LoginPage); 

    } 

} 

StartPage.html:

<ion-content class="startPage" scroll="false"> 
    <div> 
    <h1 class="startTitle">Flurn</h1> 
    </div> 
    <div class="button-bottom" bottom> 
    <button class="button button-block button-light" (click)="login()"> 
       Login 
      </button> 
    <button class="button button-block button-light" style="color:#019688;" disabled (click)="signup()"> 
       Signup 
      </button> 
    </div> 
</ion-content> 

私は私のwebrowserでコンソールにエラーを取得していません...私は何が間違っていますか?

答えて

1

筆者のコードではplunker(authロジックなし)を作成し、StartPage(氏名にはPage1という名前)が正常に動作しているようです。

あなたStartPage.tsと私のpage1.tsの唯一の違いは、このページの読み込みです:

import {LoginPage}from '../loginPage/loginPage'; 

login()方法:

login(){ 
    this.nav.push(LoginPage); 
} 

あなただけのこれらの行の前にdebugger;を追加するとどうなりますかコードを実行し、ステップごとにデバッグするコードに従います(クロムでf11)。

//This doesn't work, but if I change the page to TabsPage it works 
this.nav.setRoot(StartPage); 
関連する問題