This is my array of actors:
['Elvis', 'Jane', 'Frances']
How to pass this array within a query string in HttpClient?
I tried to use:
1)
let params = new HttpParams();
params = Params.append('actors[]', ['Elvis', 'Jane', 'Frances']);
this.http.get(url, { params: Params });
2)
let params = new HttpParams().set('actors[]', ['Elvis', 'Jane', 'Frances']);
this.http.get(url, { params: Params });
3)
let Params = new HttpParams();
Params = Params.append('actors[]', 'Jane');
Params = Params.append('actors[]', 'Elvis');
Params = Params.append('actors[]', 'Frances');
this.http.get(url, { params: Params });
1 and 2 doesn't work so as typescript gives:
[ts] Argument of type 'string[]' is not assignable to parameter of type 'string'.
3 sends only one item 'actors[]': 'Frances'
According the interface you can do that like