我工作的登錄狀態與BaQend & Ionic2,並得到在應用程序啓動一些任務。BaQend - DBready在初始化,檢查用戶
1 DBready
我不希望在每一個頁面要做到這一點:
ionViewCanEnter(): Promise<baqend> {
// Check if the Baqend SDK is ready and wait for initialization
return this.ready.resolve().then(db => this.db = db);
}
我嘗試這樣做,但它不工作:
initializeApp() {
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();
return this.ready.resolve().then(db => this.db = db);
});
}
2.檢查用戶登錄狀態
在應用程序啓動時,我應該檢查用戶的登錄狀態,如果他/她沒有登錄,它應該打開LoginModal。
ionViewWillEnter(){
if (this.db.User.me) {
console.log(this.db.User.me.username,' entered HomePage with ID ', this.db.User.me.id);
} else {
this.openLoginModal()
console.log('Hello Anonymous');
}
}
這是一個rootPage的工作代碼,但最好把它放到應用程序啓動中。
任何想法?
您能否澄清initializeApp()的來源? –
from「app/app.component.ts」 – AnDoDri