This is my array of actors:
[\'Elvis\', \'Jane\', \'Frances\']
How to pass this array within a query strin
const actors = ['Elvis', 'Jane', 'Frances'];
let params = new HttpParams();
for (const actor of actors) {
params = params.append('actors', actor);
}
this.http.get(url, { params: params });
I think the best way is to add them to parameters as a string
and have your back-end convert it back to an array
or list
.
let actorList = ['Elvis', 'Jane', 'Frances']
let params = new HttpParams();
params = params.append('actors', actorList.join(', '));
this.http.get(url, { params: params });
let actorsArray = ['Elvis', 'Jane', 'Frances'];
this.http.get(url, { params: { actors: actorsArray } });
You can do the following:
this.http.get(url, { params: { "actors[]": actorsArray } });
Here is a simple way to do it:
this.http.get(url, {
params: ['Elvis', 'Jane', 'Frances'].reduce((accumulator, name) => accumulator.append('names', name), new HttpParams())
});