Home > Mobile >  How to pass a number array within a query string in HttpClient?
How to pass a number array within a query string in HttpClient?

Time:08-05

This is my array

[1,2,4,7]

How to pass this array within a query string in HttpClient without converting to a string?

I tried to use:

let page_id = [1,2,4,7];
let params = new HttpParams();
params = Params.append('pages[]', page_id);
this.http.get(url, { params: Params });

But it returns the output like this

pages:['1,2,4,7']

What I want is

pages:[1,2,4,7]

CodePudding user response:

I think the way to do it is convert the array elements to string and then in the backend convert back this to array.

let page_id = [1,2,4,7];
let params = new HttpParams();
params = params.append('pages', page_id.join(','));
this.http.get(url, { params: params });
  • Related