我的应用程序中存在service.ts文件中错误处理程序的错误。是Cannot read property 'navigate' of undefined
。在我的service.ts文件中,代码是:
service.ts
constructor(
private http: HttpClient,
private router: Router
) { }
getIncidents(customerId): Observable<any> {
return this.http.get<any>(this.incidentApiUrl + "?customer_id=" + customerId)
.pipe(
catchError(this.handleError)
);
}
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
console.log(error.error.message)
} else {
if (error.status === 400) {
this.router.navigate(['**']);
} else {
// ....
}
}
return throwError(
console.log('Something is wrong!'));
}
这里以前的代码解决方案说将路由器注入到我拥有的构造函数中,所以我不知道还有什么可能?有想法吗?