我在我的项目中使用Angular5。我在api服务中实现了返回promises的方法
method(): Promise<any> {
return new Promise<any>((resolve,reject) => {
this.http.get(url).subscribe((response) => {
resolve(response);
}, (error) => reject(error));
});
}
在组件中,需要确保在进一步操作之前已获取所有数据。我试着这样做:
const fetch = [];
fetch.push(this.api.method());
fetch.push(this.api.method1());
fetch.push(this.api.method2());
Promise.all(fetch).then(() => alert('data fetched'));
它从未达到警戒。所有代码都获得了代码200。
当我暂停与Promise.all
一致的执行时,我发现我的承诺已转换为ZoneAwarePromise
。
当我在.then(s)
中链接它们的嵌套调用时,它运行良好为什么Promise被转换?如何让Promise.all工作?