I have an error custom handler class that implements ErrorHandler of Angular 5 core. If an error occours, handleError method have to notify it sending a snackbar material component that show up. If the error is thrown in a test button, all be fine.
If the error occours on the method ngOnInit, the snackbar doesn't work properly and it show up in a position wrong of the page and you can't dismiss it anymore.
I.E.
My Component:
export class RootPageComponent implements OnInit { constructor() {} public buttonTest() { it.happens; } ngOnInit() { it.happens; } }
This is my custom error handler:
export class ErrorHandlerCustom extends ErrorHandler { constructor(...){} handleError() { const notificationService = this.injector.get(NotificationService); // notification custom using snackbar material notificationService.exceptionError(error); } }
Results with error in ngOnInit: ngOnInit error
Click on test button: click on test button