在标题中传递数字数据会产生此错误。当更改为字符串时,错误是固定的。但任何人都可以解释Angular拦截器背后的原因是什么? Error Image
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
this.userDataService = this.injector.get(UserDataService);
const userData = this.userDataService.getUserDetails();
const tokenHeader = userData.userToken.token;
**const userIdHeader = userData.user.userId.toString();**
let authReq: any;
if (tokenHeader && userIdHeader) {
authReq = req.clone({
setHeaders: { Token: tokenHeader, UserId: userIdHeader }
});
} else {
authReq = req.clone({
setHeaders: { Token: "no_token", UserId: "no_user" }
});
}
return next.handle(authReq);
}
在这里,如果我在标有astrik的行中删除.toString(),否则它的类型为数字,我会得到图像中的错误。