【发布时间】:2018-08-25 03:04:45
【问题描述】:
Angular 6:如何使用 forkJoin
识别 api 的响应reqs = [];
if (shouldUpdatePhone) {
reqs.push(this.customerService.updatePhone(phoneUpdateRequest))
}
if (shouldUpdateAddress) {
reqs.push(this.customerService.updateAddress(addressUpdateRequest))
}
forkJoin(reqs).subscribe(result => {
console.log('result :', result);
//How to know response is from updatePhone and response from updateAddress?
});
如何识别收到的响应属于 updatePhone 和 updateAddress?根据身份,我需要向用户显示消息。
这两个 api 返回 数组(2) >
{model:true, code:200, message:null},
{model:true, code:200, message:null}
【问题讨论】:
-
forkJoin保留顺序,因此结果数组的排序方式与您列出源 Observables 的方式相同。