0

I have an error in my application for an error handler in a service.ts file. It is Cannot read property 'navigate' of undefined. In my service.ts file the code is:

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!'));
  }

The previous code solutions on here say to inject the router in the constructor which I have, so I don't know what else it could be? Any idea?

rob
  • 291
  • 3
  • 9
  • 21

0 Answers0