我想从获取请求中获取查询参数。拦截器代码是这种方式,
export class FixtureInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req);
}
}
我试图使用这样的get方法来获取参数,
req.params.get('category');
但它总是使我返回null。我的api呼叫就是这样,
getValue() {
return this.http.get('http://139.49.10.175:3000/laundryItems?category=2&type=4');
}
我需要上述API调用的类别和类型的值
显然,直接放在url中的参数没有出现在中req.params
,该参数应该起作用:
getValue() {
return this.http.get('http://139.49.10.175:3000/laundryItems', {params: {category: '2', type: '4'}});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句