question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NbToastrService exception

See original GitHub issue

Issue 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: image

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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
evtkhvchcommented, Sep 9, 2021

This error occurs when you try to invoke toastrService.show in constructor of root component (that exist <nb-layout>). In this moment layout container hasn’t attached yet. So, you should invoke toastrService.show when layout container has attached. ex: in OnInit hook, or in a child components. Hope it helps.

0reactions
JabCorpcommented, Jun 7, 2021

Work around provide here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Toastr Angular UI Component - Nebular - GitHub Pages
The NbToastrService provides a capability to build toast notifications. ... NbToastrService.show(message, title, config) accepts three params, title and config ...
Read more >
No provider for InjectionToken ToastConfig! in jasmine spec ...
Hi everybody! First time asking question here, hoping for some help. I'm currently developing a Electron+Angular application and I'm finally ...
Read more >
cannot read property of undefined (reading 'subscribe') unit test
SpyObj<NbToastrService>; let dialogService: jasmine. ... of undefined (reading 'kind') Angular 13 Webpack Exception: TypeError: Cannot read properties of ...
Read more >
Global Error Handling in Angular - Philipp Kief
A not always so popular but for the end user enormously important topic is the interception of errors. Even if an application has...
Read more >
Source - GitHub
Inject `NbToastrService` into the required component. call `NbToastrService.show(. ... **tabset:** fix exception, when renders conditionally with \*ngIf ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found