[英]Updating component variable after all Ajax requests completed
我有一个 URL 列表,我正在调用每个 URL 的 Ajax 请求,例如
private getDayData(urls: string[]) {
const sunrise = [];
from(urls).pipe(
concatMap(url => ajax(url)),
map((ajxRes: any) => ({
date: ajxRes.response.location.time[0].date,
sunrise: ajxRes.response.location.time[0].sunrise,
sunset: ajxRes.response.location.time[0].sunset
}))
).subscribe(response => {
sunrise.push(response);
console.log(sunrise);
});
}
在得到所有结果后,我需要返回这个sunrise
数组。 每次 Ajax 请求完成时的subscribe
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.