user13520940
user13520940

Reputation: 143

Angular 9 http.Get request with paramaters

I am trying to send query parameters with a get request. This code always has an empty query {}. What am I missing?

let p = new HttpParams().set('Test', "7878");
return this.http
  .get<Response>(environment.baseAPIUrl + route, 
    { 
      withCredentials: false, 
      headers: requestHeaders, 
      params: p, 
      responseType, 
      observe: observe as 'body'
    } 
  );

Upvotes: 0

Views: 423

Answers (1)

TmTron
TmTron

Reputation: 19381

Basically your use of HttpParams seems okay and it's working for me.

Open my Stackblitz Example:

  • open the dev-tools (F12 in Chrome)
  • go to the network tab
  • now Refresh the stackblitz-browser frame: everything looks good:

enter image description here

just note, that the error-message (1) will not include the url-parameters

Upvotes: 1

Related Questions