我正在与BaQend & Ionic2合作,并尝试在App中完成一些任务。
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.检查用户登录状态
在App上,我应该检查用户的登录状态,如果他/她没有登录,它应该打开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的一个工作代码,但最好将其导入应用程序启动程序。
有什么想法吗?
发布于 2017-08-21 09:37:22
很好的观点,
我们更新了离子起动器。我们将DBReady检查移到根视图。在我们的起步阶段,那就是tabs.component.ts。然后,Rootview在呈现子视图之前总是等待db。
如果您也更新了db.service.ts,现在也可以使用从SDK导出的db。
import { db } from "baqend";https://stackoverflow.com/questions/45792121
复制相似问题