Within my app.module.ts
, I've set up the following code:
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpModule
],
providers: [
{provide: ErrorHandler, useClass: MyExceptionHandler}
],
bootstrap: [AppComponent],
})
export class AppModule {}
Next, in my MyExceptionHandler
:
import { Injectable } from "@angular/core"
import { Router } from "@angular/router"
@Injectable()
export class MyExceptionHandler {
constructor (private _router: Router) {}
handleError(error:any):void {
...
}
}
Unfortunately, an error is popping up saying:
Error: Error: Provider parse errors
If I treat MyExceptionHandler as a normal provider, everything works smoothly. It seems like the ErrorHandler is being executed before the Router is fully instantiated. Any suggestions on how to fix this issue?