Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get query params of a request in interceptor Angular

I want to get the query params from an get request. Interceptor code is this way,

export class FixtureInterceptor implements HttpInterceptor {
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
       return next.handle(req);
  }
}

i tried to get the params using get method like this ,

req.params.get('category');

but it returns me null always. My api call is this way ,

getValue() {
     return this.http.get('http://139.49.10.175:3000/laundryItems?category=2&type=4');
}

i need value of category and type from above API call

like image 679
Sksaif Uddin Avatar asked Jan 26 '26 08:01

Sksaif Uddin


1 Answers

Apparently params directly putted in url doesn't appear in req.params, this one should work:

  getValue() {
    return this.http.get('http://139.49.10.175:3000/laundryItems', {params: {category: '2', type: '4'}});
  }
like image 75
Buczkowski Avatar answered Jan 28 '26 03:01

Buczkowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!