【发布时间】:2020-05-21 00:43:54
【问题描述】:
例如,我需要帮助来获取来自对象数组的两个 HTTP GET 响应并将它们组合到一个对象数组中
如果可能的话,我希望使用 rxjs 的 http 数组更有可能得到一个数组中包含所有 3 个对象的响应
如下图
[{...}, {...}, {...}]
.ts
incidents$ = this.incidentService.getAll();
otherIncidents$ = this.otherIncidentsService.getAll();
ngOnInit() {
this.incidents$.subscribe(res => {
console.log('first http GET request', res)
})
this.otherIncidents$.subscribe(res => {
console.log('second http GET request', res)
})
控制台
second http GET request [{…}]
0: {incidentNumber: 19418, createdByName: "User", execSummaryFlag:
false, followupEmail: null, …}
length: 1__proto__: Array(0)
exec-summary.component.ts:140
first http GET request (2) [{…}, {…}]
0: {incidentNumber: 19380, createdByName: "User", execSummaryFlag: false,
followupEmail:null, …}
1: {incidentNumber: 19399, createdByName: "User", execSummaryFlag: false,
followupEmail: null, …}length: 2__proto__: Array(0)
【问题讨论】: