I'm newbie to RxJs. I could not find how to do it. I have a large number of nested http requests in my master data. And I want to get all the http requests and combine them all in my main stream.
My example main stream data as:
[
{
id: '123',
name: 'nameVal1',
salary: [
{ href: 'http://example.com/salary/1' },
{ href: 'http://example.com/salary/2' }
],
address: {
href: 'http:/example.com/address'
}
},
{
id: '456',
name: 'nameVal2',
salary: {
href: 'http://example.com/salary/1'
},
address: {
href: 'http:/example.com/address'
}
}
];
Example salary object:
{
salary: '1000€',
month: 2
}
Example address object:
{
country: 'UK',
city: 'London',
postalCode: '123'
}
My main stream is array of objects like above and after get the main stream, I want to get all nested data and combine them all the main stream like that:
[
{
id: '123',
name: 'nameVal1',
salary: [
{
salary: '1000€',
month: 2
},
{
salary: '500€',
month: 3
}
],
address: {
country: 'UK',
city: 'London',
postalCode: '123'
}
},
{
id: '456',
name: 'nameVal2',
salary: [
{
salary: '2000€',
month: 3
}
],
address: {
country: 'UK',
city: 'London',
postalCode: '456'
}
}
];
this.service.mainHttpReq().pipe(
map(users => {
users.salary.forEach(salaryItem => {
return fetch(salaryItem.href);
});
})
).subscribe(usersData => {
console.log('Users Data :', usersData);
});