How to pass url arguments to a HTTP request on Angular?

Forums AngularHow to pass url arguments to a HTTP request on Angular?
Staff asked 3 weeks ago

How can I Pass parameter as query string in angular?

Answers (1)

Add Answer
monika gabani Marked As Accepted
Staff answered 3 weeks ago

We add the URL parameters using the helper class Httparams.  The Httparams is passed as one of the arguments to HttpClient.get method.

To use Httparams, you need to import it first as shown below.

import { HttpClient,HttpParams } from ‘@angular/common/http’;

Then create an instance of the HttpParams class.

const params = new HttpParams()
  .set('page', PageNo)
  .set('sort', SortOn);

And then  call the HttpClient.get method passing the params as the argument.

return this.httpClient.get<repos[]>(this.baseURL + 'users/' + userName + '/repos',{params})
 

 

 

Subscribe

Select Categories