Demiro-FE-Architect
Demiro-FE-Architect

Reputation: 3740

Angular4: Http -> HttpClient - requestOptions

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 :(

Upvotes: 25

Views: 36954

Answers (1)

Andrei Matracaru
Andrei Matracaru

Reputation: 3671

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

Upvotes: 22

Related Questions