【发布时间】:2021-08-27 14:02:04
【问题描述】:
假设我想进行 2 个返回数据的 http 调用,并且我只想在两个 http 调用都返回数据后调用一个函数,以便我可以合并两个数据。
ngOnInit(): void {
this.getData();
}
getData() {
this.func1();
this.func2();
this.func3();
}
async func1() {
this.service.call1().subscribe((data) => {
this.data1 = data;
});
}
async func2() {
this.service.call2().subscribe((data) => {
this.data2 = data;
});
}
func3() {
//this should only get called when func1 and func2 have finished their http calls.
}
【问题讨论】:
-
请edit您的问题标题不仅仅是重复标签中可用的信息。您的标题应该描述您遇到的问题或您提出的问题,这种方式对正在扫描搜索结果列表以试图找到解决问题的本网站的未来用户有意义。您当前的标题在这方面没有任何作用 - 它只是标签的反刍。
-
@Jay 不知道为什么你改变了接受的答案。我的回答有什么遗漏吗?
标签: angular asynchronous async-await