我有以下代码,我想从后端发送的标头参数X-OBSERVATORY-AUTH中获取令牌。我收到以下错误: 错误TypeError:无法读取未定义的属性“ get”。我该怎么办?
login( username: string, password: string) {
var user: User = { username: username, password: password };
this.http
.post<any>(
"http://localhost:3000/api/auth",user)
.subscribe((response: Response) => {
const token = response.headers.get('X-OBSERVATORY-AUTH');
this.token = token;
if (token) {
this.isAuthenticated = true;
// this.userId = response.body._id;
// this.isAdmin=response.body.isAdmin;
this.authStatusListener.next(true);
this.saveAuthData(token, this.userId, this.isAdmin);
}
});
}