Angular 如何在Ionic3中有条件地设置rootPage
我正在尝试为应用程序中的第一个用户设置教程页面,并为其他用户设置登录页面。如果用户已经阅读了教程页面,我将在localstorage中设置键值Angular 如何在Ionic3中有条件地设置rootPage,angular,ionic2,ionic3,ionic-native,Angular,Ionic2,Ionic3,Ionic Native,我正在尝试为应用程序中的第一个用户设置教程页面,并为其他用户设置登录页面。如果用户已经阅读了教程页面,我将在localstorage中设置键值 export class MyApp { rootPage: any = LoginPage; constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) { platform.ready().then(() => {
export class MyApp {
rootPage: any = LoginPage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
statusBar.styleDefault();
if(!localStorage.getItem( 'tutorial' )) {
this.rootPage = TutorialPage;
}
splashScreen.hide();
});
}
}
上面的代码工作正常,但设置教程页面时有延迟,登录页面先查看,然后出现教程页面。我想知道我是以正确的方式做这件事还是遗漏了什么?请使用以下代码
export class MyApp {
rootPage: any;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
statusBar.styleDefault();
if(!localStorage.getItem( 'tutorial' )) {
this.rootPage = TutorialPage; // user can user this.nav.setRoot(TutorialPage);
}else{
this.rootPage = LoginPage; // user can user this.nav.setRoot(LoginPage);
}
splashScreen.hide();
});
}
}
我希望它能为您工作。请使用以下代码
export class MyApp {
rootPage: any;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
statusBar.styleDefault();
if(!localStorage.getItem( 'tutorial' )) {
this.rootPage = TutorialPage; // user can user this.nav.setRoot(TutorialPage);
}else{
this.rootPage = LoginPage; // user can user this.nav.setRoot(LoginPage);
}
splashScreen.hide();
});
}
}
我希望它对您有用。删除
rootPage:any=LoginPage代码>仅使用根页面:任意编码>并将else
块放入constructor
。感谢@hrdkisback的回答。成功了!删除rootPage:any=LoginPage代码>仅使用根页面:任意编码>并将else
块放入constructor
。感谢@hrdkisback的回答。成功了!