I want to combine two identical type observables in Angular2 and return an observable of the same type in a function.
My goal is to:
transform this setup:
obs1.subscribe(obs => console.log(obs))
(where I receive):
{
count: 10,
array: <someObservable[]>
}
and
obs2.subscribe(obs => console.log(obs))
(where I get):
{
count: 10,
array: <someObservable[]> (different objects)
}
into:
{
count: 10 (always the same number),
array: <combined array from obs1 and obs2>
}
How can I achieve this easily? (It might be simple for junior level angular developers, but as a newbie in this field, I need to do it quickly). Thanks in advance.
---UPDATE---
considering this code snippet :
const obs2 = obs1.pipe(
switchMap(value => {
return this._loadMoreTextSearchSub.asObservable()
.pipe(pairwise(),
map(params => this.getPagingParameters(params[0], params[1])),
switchMap(request),
map(response => response.packages),
scan<SearchPackage[]>((all, current) => {
return [...all, ...current];
},
value.packages
));
}))
.subscribe(data => console.log('sec', data));
It returns an array of objects. How can I encapsulate that array within an object and add an extra property - 'count'?
Current:
[{...}, {...}, {...}, {...}]
Desired:
{count: some_number, array: [{...}, {...}, {...}]}