Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda