How to set HTTP Params in Angular without the key?

398 Views Asked by At

Whenever I try to set HttpParams it's like:

let params = new HttpParams()
    .set('someKey', this.key)

but my API URL looks like this:

/api/something/99999/item

So how to set this.key like this which is 99999?

2

There are 2 best solutions below

2
On BEST ANSWER

From my understanding, you don't need HttpParams.

You can directly pass this.key to the url like this :

const url = `api/something/${this.key}/item`;

And after do the http call with the url.

1
On

Just bind to the url without the HttpParams

this.http.get('/api/something/' + this.key + '/item')