Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Angular combine and transform multiple http requests with forJoin Rxjs operator

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

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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);
      }

Forked Example

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!