I want to inject the Angular Router into my HttpInterceptor. Unfortunately, the following error is thrown in the browser console:
TypeError: this.router is undefined
I've added this to my constructor as usual:
constructor (private router: Router) {
}
Additionally, I did the following in my providers array inside the app.module.ts:
{
provide: HTTP_INTERCEPTORS,
useClass: MyService,
multi: true,
deps: [Router]
}
I want to use the current url inside an if statement in my error handler to provide specific functionalities for different routes:
myErrorHandler(error: HttpErrorResponse) {
if (this.router.url === 'test') {
// do something
} else {
return throwError(error).pipe(
// do something
);
}
}
What am I doing wrong?