【发布时间】:2017-11-03 23:08:39
【问题描述】:
在我的 Ionic 2 应用程序中,有两个页面,但在 ProfilePage 加载后,它会推送 LoginPage,然后刷新它并且页面变为空白。有谁知道为什么会这样?
这是我的代码
app.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { ProfilePage } from '../pages/profile/profile';
import { LoginPage } from '../pages/login/login';
import { AuthService } from '../services/auth/auth.service';
@Component({
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class AuthApp {
rootPage: any = ProfilePage;
constructor(platform: Platform, private auth: AuthService) {
platform.ready().then(() => {
StatusBar.styleDefault();
auth.startupTokenRefresh();
});
}
}
profile.ts
import {Component} from '@angular/core';
import {AuthService} from '../../services/auth/auth.service';
import { NavController } from 'ionic-angular';
import { LoginPage } from '../login/login';
@Component({
templateUrl: 'profile.html',
})
export class ProfilePage {
constructor(public auth: AuthService, public navCtrl: NavController) {
}
ngOnInit() {
console.log(this.auth.authenticated())
if (!this.auth.authenticated()) {
this.navCtrl.setRoot(LoginPage);
}
}
}
login.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
templateUrl: 'login.html',
})
export class LoginPage {
authType: string = "login";
error: string;
constructor(public navCtrl: NavController) {}
}
关于我做错了什么有什么建议吗?为什么LoginPage推送时会刷新?
【问题讨论】:
-
控制台有什么东西吗?
-
控制台中没有任何内容