2017-08-21 34 views
1

我工作的登錄狀態與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的工作代碼,但最好把它放到應用程序啓動中。

任何想法?

+0

您能否澄清initializeApp()的來源? –

+0

from「app/app.component.ts」 – AnDoDri

回答

1

非常好的一點,

我們已經更新了我們的離子起動器。我們將DBReady檢查移到了根視圖。 在我們的初學者中是tabs.component.ts。 Rootview在呈現子視圖之前總是等待數據庫。

如果您也更新db.service.ts,那麼您現在也可以使用從SDK導出的數據庫。

import { db } from "baqend"; 
+0

以及如何實現登錄檢查? – AnDoDri

+1

登錄檢查也可以在根視圖中執行。 –

+0

有沒有辦法將這個實現到app.component.ts?我不使用標籤,我只是使用sidemenu。 – AnDoDri