【发布时间】:2020-12-06 18:15:12
【问题描述】:
async getRecords(): Promise<Records[]> {
this.subRecords = await this.afs.collection<Records>('records')
.valueChanges()
.subscribe((data: Records[]) => {
console.log('log before data saved');
this.records = data as Records[];
});
console.log('log before return');
return await this.records;
}
所以我的问题是,我需要以正确的顺序执行此代码。 log before data saved 在返回后执行。所以我并没有真正及时保存我的数据。我需要一种方法来命令代码的执行,以便函数返回我的 this.records 数组中的记录。
【问题讨论】:
标签: angular typescript firebase asynchronous google-cloud-firestore