为了账号安全,请及时绑定邮箱和手机立即绑定

使用 async/await 时函数未按正确顺序触发

使用 async/await 时函数未按正确顺序触发

呼唤远方 2021-06-04 16:25:00
在 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?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 183 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信