use Observable.combineLatest
or Observable.forkJoin
, see their differences here.
Observable.combineLatest(this.test3, this.test4);
Observable.forkJoin(this.test3, this.test4);
when you subscribe to Observable.combineLatest
, you will get result like below:
[response3, response4]
and you can use Array.reduce
to combine those two Observables' result
// combineLatest
Observable.combineLatest(this.test3, this.test4)
.subscribe(res => {
this.concatResult = res.reduce((pre, next) => {
return [].concat(pre.json().data, next.json().data);
})
});
// forkJoin
Observable.forkJoin(this.test3, this.test4)
.subscribe(res => {
this.concatResult = res.reduce((pre, next) => {
return [].concat(pre.json().data, next.json().data);
})
});
refer this plunker demo