我正在通过调用该类的方法来执行获取请求AuthService
:
return this.http.post<any>('url',{
"username": username,
"password":password
}, this.httpOptions).pipe(catchError(this.errorHandler));
来自另一个班级:
this.authService.login(this.username,this.password).subscribe(response =>{
console.log("Response " + response.token);
});
这里的问题是property token does not exist in type HttpEvent<any>
。如果我运行它并尝试打印它,它会正确打印,但代码中的错误仍然存在。我尝试过改变类型any
到带有代表我的响应的字段的自定义接口,但错误是相同的,因为它始终是 HttpEvent。
我该如何解决这个问题?
try this
this.authService.login(this.username,this.password).subscribe((response : any) =>{
console.log("Response " + response.token);
});
或者如果你想让它输入
return this.http.post<{token: string}>('url',{
and then
this.authService.login(this.username,this.password).subscribe((response : {token: string}) =>{
console.log("Response " + response.token);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)