4

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.

2
  • why do you need to add same key twice? GET HTTP request uses key=value structure Commented Oct 12, 2017 at 13:54
  • 3
    I know that it is not pretty. But the api expects the values this way. Commented Oct 12, 2017 at 13:59

1 Answer 1

8

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();
Sign up to request clarification or add additional context in comments.

1 Comment

In our project this is broken after upgrade from Angular 7 to Angular 15. Still searching a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.