Reputation: 925
I have this array['ca','ba','es']
How can i covnert to object so that i have r=ca, r=ba, r=es.
So in queryParams when i add i will have url something like this:
r=ca&r=ba&r=es
I tried something like this but its not working:
let obj = this.queries.r.reduce(function(acc, cur, i) {
'r' = cur;
return acc;
}, {});
Because r is not valid as param.Any suggestion how can i fix this?
Upvotes: 0
Views: 624
Reputation: 725
Since you are using an old version. Latest HttpParams fromObject won’t work.
Try something like this.
let params = new HttpParams()
['ca','ba','es'].forEach(item => {
params = params.append(“r”, item);
}
Upvotes: 0
Reputation: 725
Try this. I think this should work in your case.
Const params = new HttpParams({fromObject: { r: yourArrayHere }}).
Make sure you import HttpParams from @angular.
Hope that helps!
Upvotes: 1