Angular4: Http -> HttpClient - requestOptions

DS_web_developer picture DS_web_developer · Aug 21, 2017 · Viewed 34.3k times · Source

So, I am trying to migrate from 'old' http to the new httpClient

with the http client I am using this format in my service:

return this.http.get(environment.api+ '.feed.json', requestOptions)

how do I use this in httpClient?

tried many thiungs... including

return this.http.get(environment.api+ '.feed.json', {params: requestOptions.params})

but getting a type missmatch :(

Answer

Andrei Matracaru picture Andrei Matracaru · Aug 21, 2017

Try this:

const requestOptions = {
  params: new HttpParams()
};

requestOptions.params.set('foo', 'bar');

this.http.get(environment.api+ '.feed.json', requestOptions );

Here is also the link to the docs describing how to do that with examples for headers and URL Parameters: HttpClient