Circular dependency in DI detected for ApplicationRef
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other...
Current behavior
When trying to inject the HotToastService in a custom ErrorHandler I get the following error:
Error: NG0200: Circular dependency in DI detected for ApplicationRef. Find more at https://angular.io/errors/NG0200
at throwCyclicDependencyError (core.js:216)
at R3Injector.hydrate (core.js:11408)
at R3Injector.get (core.js:11232)
at injectInjectorOnly (core.js:4728)
at ɵɵinject (core.js:4732)
at Object.ViewService_Factory [as factory] (ngneat-overview.js:437)
at R3Injector.hydrate (core.js:11412)
at R3Injector.get (core.js:11232)
at injectInjectorOnly (core.js:4728)
at ɵɵinject (core.js:4732)
Other components can inject the service without any issues.
Expected behavior
Should be able to inject the service in the custom error handler.
Minimal reproduction of the problem with instructions
Setup the library and the following service:
@Injectable()
export class AppErrorHandlerService implements ErrorHandler {
constructor(private readonly toast: HotToastService) {}
handleError(error: any): void {
this.toast.error('Unexpected error.');
console.error(error);
}
}
Provide via { provide: ErrorHandler, useClass: AppErrorHandlerService }.
The issue might’ve been introduced with Angular v12, as another project on v11 has this pattern working.
Environment
"@angular/core": "~12.0.2",
"@ngneat/hot-toast": "^2.0.2",
"@ngneat/overview": "^1.0.0",
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Circular dependency in DI detected for ApplicationRef. How to ...
I am a beginner in Angular and tried to implement global error handling in the application for this purpose I create appErrorHandler class...
Read more >NG0200: Circular dependency in DI detected while ... - Angular
Break this loop (or circle) of dependency to resolve this error. This most commonly means removing or refactoring the dependencies to not be...
Read more >[Debugging] Circular dependency in DI detected - YouTube
In this video, you'll learn what the error " Circular dependency in DI detected " means, how to debug it, and prevent it...
Read more >“Circular dependency detected” in Angular 11, how to solve it?
Circular Dependency in Angular. Problem. We have one service named SharedService and a component named LoginDialogComponent.
Read more >Circular dependency in DI detected - ZimBaroo's Geeks Sharing
I have faced two cases of circular dependencies a lot. So, here is the explanation. home.page.ts import { Component } from '@angular/core'; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can get
HotToastServicefromInjector:Ref: https://github.com/scttcper/ngx-toastr/issues/327#issuecomment-361304175
Saved my day! Thanks!