【发布时间】:2018-12-13 08:35:07
【问题描述】:
如上所述,我想在一个函数中使用注入到根目录中的服务,以便在 401 错误后注销用户。在我的一个 http 请求中发生错误后,该函数在管道中被调用。不幸的是,我收到如下错误:
错误类型错误:无法读取未定义的属性“注销”
401错误后。似乎该函数是在不同的范围内调用的。我尝试通过 injector.get 注入服务,将我的服务和错误功能设置为公开,但没有任何效果。
还有其他机会解决这个问题吗?
constructor(private httpClient: HttpClient, private authenticationService: AuthenticationService) {}
private handleError(error: HttpErrorResponse) {
if (error.status === 401) {
this.authenticationService.logout();
}
return throwError('Something bad happened; please try again later.');
}
getSomething(): Observable<HttpResponse<Model>> {
return this.httpClient.get<Model>(this.apiEndpoint, {
observe: 'response'
}).pipe(
catchError(this.handleError)
);
}
【问题讨论】:
标签: angular service scope pipe angular6