Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda