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

178
Views
Angular make a get passing array

I'm trying to make an api call passing an array of id

in my page.ts:

this.myService.getPassingID(['1', '2'])
 .subscribe((val) => console.log("val", val))

in my service:

getPassingID(id): Observable<any>{
let params = new HttpParams()
      .set("id", id)
let url = apiURL 
return this.http.get(url, {params});
}

I have tried in this way but I receive 500 error. How can I pass array in api call?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can pass it in two ways.

#1 Stringify the array while passing it into params and then send it to the HTTP call

let params = new HttpParams().set("id", JSON.stringify(id));

This needs you to parse the respective param at your receiving API backend.

JSON.parse(params.id)

and use it further.

#2 Append all the elements of the array as comma(,) separated values into the id param.

let params = new HttpParams();
params = params.append('id', id.join(','));

This can be accessed and split on comma(,) at the backend.

let idArray = params.id.split(',');

and use it further.

about 4 years ago · Juan Pablo Isaza 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!