NbToastrService exception
See original GitHub issueIssue type
I’m submitting a … (check one with “x”)
- bug report
Issue description
Current behavior:
I am trying to implement an error handler which uses the NbToastrService but I am getting a console error:
I traced it back to here: https://github.com/akveo/nebular/blob/d3ba6ab42b88ded18a3285c4527372b45cc33065/src/framework/theme/components/cdk/adapter/overlay-container-adapter.ts#L30
I have tried manually providing the NB_DOCUMENT
token in the app module providers e.g. { provide: NB_DOCUMENT, useExisting: DOCUMENT }
and I have injected this token in to my service and the document is available when I call the toastr service so I don’t know why it won’t work.
Expected behavior:
I would like to be able to use this service to catch errors as the app is initializing.
Steps to reproduce:
Call the toastrService
in the constructor of the app component
Related code:
StackBlitz Sample of the issue
constructor(private toastrService: NbToastrService) {
// doesn't work
const toastRef: NbToastRef = this.toastrService.show("Message", "Doesn't work");
}
Other information:
Angular 9/10 both display this issue
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
This error occurs when you try to invoke
toastrService.show
inconstructor
of root component (that exist<nb-layout>
). In this moment layout container hasn’t attached yet. So, you should invoketoastrService.show
when layout container has attached. ex: inOnInit
hook, or in a child components. Hope it helps.Work around provide here