我有一个返回表数据的请求,需要像等待数据加载的承诺一样处理该请求。为了将数据加载到表中,我必须使用异步/等待,但这会弄乱所有其他函数/方法。
如何在 ngOnInit() 上不使用 async/wait 的情况下将数据存储在 currentList 中?或者还有其他方法吗?
async getEducationList(): Promise<any> {
return this.educationList = await this.applicationClient.getEducations()
.toPromise()
.then((res) => {
this.educationListAll = res;
});
}
async ngOnInit() {
await this.getEducationList();
this.currentList = this.educationListAll;
}
注意 - this.applicationClient.getEducations() 是一个 Observable
试试这个方法
async ngOnInit() : Promise<void> {
this.currentList = await this.applicationClient.getEducations().toPromise();
this.initTable(data);
}
initTable(data) {
// Some code to handle the data
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)