I am combining multiple http requests with forkJoin rxjs operator.
fetchUsers() {
const userIds = [1, 2, 3];
const url = 'https://jsonplaceholder.typicode.com/users';
forkJoin(userIds.map(id => this.http.get(`${url}/${id}`))).subscribe(
console.log
);
}
So, then I subscribe I get three objects, but I want to mutate that objects and get structure like this
[{id:1, user: Object}, {id:2, user: Object}, {id:3, user:Object}];
I have tried using of operator but I get
[{id:1, user: Observable}]
structure. This is my stackblitz link https://stackblitz.com/edit/angular-ivy-uikppg?file=src%2Fapp%2Fapp.component.ts. Thanks
You should use rxjs map operator to transform data instead of using of operator inside forkJoin
fetchUsers() {
const userIds = [1, 2, 3];
const url = 'https://jsonplaceholder.typicode.com/users';
forkJoin(
userIds.map(id => this.http.get(`${url}/${id}`).pipe((map(user=>({
id,user
})))))
).subscribe(console.log);
}