0

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 Answers2

0

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.

Johan Rin
  • 1,900
  • 2
  • 20
  • 42
  • i know this way, but I would prefer to use HttpParams, if it's possible of course –  Dec 03 '18 at 14:49
  • It is not possible. If you are using `HttpParams`, it will result a URL with Parameters like `api/heroes/?name=foo` as shown [here](https://angular.io/guide/http#url-parameters) – Johan Rin Dec 03 '18 at 14:55
0

Just bind to the url without the HttpParams

this.http.get('/api/something/' + this.key + '/item')
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80