This is my array of actors:
[\'Elvis\', \'Jane\', \'Frances\']
How to pass this array within a query strin
Works on Angular 6.0.6:
private getParams(query) {
let params: HttpParams = new HttpParams();
for (const key of Object.keys(query)) {
if (query[key]) {
if (query[key] instanceof Array) {
query[key].forEach((item) => {
params = params.append(`${key.toString()}[]`, item);
});
} else {
params = params.append(key.toString(), query[key]);
}
}
}
return params;
}
Result:
/api/message?page=1&per=2&order_by=name&order_direction=asc&base_object%5B%5D=2&base_object%5B%5D=1