1

I'm getting an array of Id's like below:-

id=[1,2,3,4]

How to dynamically pass those value from array id to a parameter of a API request like this in angular:-

this.http.get(`/api/request?num=1,2,3,4`);

2 Answers 2

3
const ids: string = id.join(',')
this.http.get(`/api/request?num=${ids}`);

Or

const ids: string = id.join(',')
const options = { params: new HttpParams().set('num', ids) };
this.http.get('/api/request', options);

Angular Doc

Sign up to request clarification or add additional context in comments.

Comments

1

You can provide the params like this:

const num = [1,2,3,4]
this.http.get(`/api/request`, {params: {num}});

Comments

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.