【发布时间】:2019-12-20 11:56:07
【问题描述】:
我有这样的服务
async getBirthdays() {
const user = await this.authSP.getUserInfo();
let bdays = [];
return await new Promise<any>((resolve) => {
this.angularFire.database.ref("birthdays").orderByChild("creator_user_id").equalTo(user.uid).once("value", (snapshot) => {
snapshot.forEach(function (childSnapshot) {
const value = childSnapshot.val();
value.$key = childSnapshot.key;
bdays.push(value);
});
});
resolve(bdays);
});
}
这个承诺返回这个对象数组
在我的组件中,我只是尝试显示头像值:
this.birthdays = await this.birthdaySP.getBirthdays().then(res => {
var data = res.map(t=>t.avatar);
console.log(data);
});
但是console.log(data)返回一个空数组。
感谢任何帮助
【问题讨论】:
标签: javascript firebase ionic-framework firebase-realtime-database promise