在 Angular 服務中,我創建了以下函數:getListKey(user) { firebase.database().ref(`userprofile/${user.uid}/list`).once('value').then(snapshot => { console.log(snapshot.val()) this.listKey = snapshot.val() return this.listKey })}我想在加載時在另一個文件中調用這個函數,并將返回的值分配給listKey服務中的全局變量,以用于組件中的另一個函數。但是,即使使用async/檢索數據,第二個函數也會觸發await。這是我的組件中的相關部分:this.afAuth.authState.subscribe(async (user: firebase.User) => { await this.fire.getListKey(user); this.fire.getUserList(this.fire.listKey).subscribe(lists => {...}) ...}我怎樣才能getUserList()等待listKey?
使用 async/await 時函數未按正確順序觸發
呼喚遠方
2021-06-04 16:25:00