我尝试将jwt Web令牌挂接到我的传出请求,显示添加了拦截器“ ERROR TypeError:无法读取未定义的属性'length'”后,我使用了拦截器方法。 当拦截器文件被删除时,应用程序正常工作
这是我的拦截类
答案 0 :(得分:0)
这是一个简化的版本,但在我的应用程序中它就像一个魅力:
public intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
req = this.addAuthHeader(req);
}
addAuthHeader(request) {
const r: HttpRequest<any> = request.clone({
headers: new HttpHeaders({
Authorization: 'Bearer ' + this.authService.getToken()
})
});
return r;
}
供参考-> how-to-add-multiple-headers-in-angular-5-httpinterceptor和interceptor-angular-4-3-set-multiple-headers-on-the-cloned-request
致谢