【发布时间】:2022-01-08 12:22:01
【问题描述】:
晚上好,我正在尝试设置身份验证服务,但登录功能一直显示此错误:
类型 'Observable' 不可分配给类型 '可观察的
'。类型“ArrayBuffer”缺少 来自“HttpResponse”类型的以下属性:body、type、 克隆、标题和另外 4 个。
功能如下:
login(user:User): Observable<HttpResponse<User>>{
return this.http.post<User>(`${this.apiUrl}/login`, user, {observe: Response});
}
用户模型界面是:
export interface User {
username: string;
password:string;
}
我调用这个函数是我的登录组件:
onLogin(user: User):void{
this.subs.add(
this.authService.login(user).subscribe(
(response) =>{
this.authService.addTokenToCache(response.headers.get('Jwt-Token') || '{}');
// this.authService.addUserToCache(response.body|| '{}');
this.router.navigateByUrl("/home");
this.showLoading=false;
},
(error: HttpErrorResponse)=>{
alert(error.message);
this.showLoading=false;
}
))
}
我该如何解决这个问题?
【问题讨论】:
标签: angular typescript api authentication rxjs