有什么方法可以在角度8的拦截器上传递查询和参数
const params = new HttpParams()
.set('lang', localStorage.getItem('language'))
.set('android_version', '1')
Run Code Online (Sandbox Code Playgroud)
Pra*_*lan 13
您可以使用方法修改请求 HttpRequest#clone。
@Injectable()
export class CustomInterceptor implements HttpInterceptor {
constructor() {}
intercept(req: HttpRequest<any>, next: HttpHandler) {
const newReq = req.clone({
params: (req.params ? req.params : new HttpParams())
.set('lang', localStorage.getItem('language')) /*.... add new params here .....*/
});
return next.handle(newReq);
}
}
Run Code Online (Sandbox Code Playgroud)
参考: https: //angular.io/guide/http#immutability
| 归档时间: |
|
| 查看次数: |
5223 次 |
| 最近记录: |