Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate parameters in Angular $http

I want to add multiple parameters with the same name to a request URL. I'm using Angular's $http.

The URL should look like this: http://myBaseUrl?name1=value1&name1=value2...

I know that it is possible to make something like this when I set the values as an array: http://myBaseUrl?name1=value1,value2...

But it has to be like the first one.

like image 343
chocolate cake Avatar asked Oct 26 '25 18:10

chocolate cake


1 Answers

If you're using HttpClient you can use HttpParams for this.

let params = new HttpParams();

// Assign parameters
params = params.append('firstParameter', 'valueOne');
params = params.append('firstParameter', 'valueTwo');

// Get request
this.http.get(`http://example.com`, { params }).subscribe();
like image 102
Owain van Brakel Avatar answered Oct 29 '25 09:10

Owain van Brakel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!