在 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?
添加回答
举报
0/150
提交
取消