mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
Apply editorial suggestions for peer review. Co-authored-by: Tiffany Davis <88161089+TMDavisGoogle@users.noreply.github.com> PR Close #45325
21 lines
1.1 KiB
Markdown
21 lines
1.1 KiB
Markdown
@name Circular Dependency in DI
|
|
@category runtime
|
|
@videoUrl https://www.youtube.com/embed/CpLOm4o_FzM
|
|
@shortDescription Circular dependency in DI detected while instantiating a provider
|
|
|
|
@description
|
|
A cyclic dependency exists when a [dependency of a service](guide/hierarchical-dependency-injection) directly or indirectly depends on the service itself. For example, if `UserService` depends on `EmployeeService`, which also depends on `UserService`. Angular will have to instantiate `EmployeeService` to create `UserService`, which depends on `UserService`, itself.
|
|
|
|
@debugging
|
|
Use the call stack to determine where the cyclical dependency exists.
|
|
You will be able to see if any child dependencies rely on the original file by [mapping out](guide/dependency-injection-in-action) the component, module, or service's dependencies, and identifying the loop causing the problem.
|
|
|
|
Break this loop \(or circle\) of dependency to resolve this error. This most commonly means removing or refactoring the dependencies to not be reliant on one another.
|
|
|
|
<!-- links -->
|
|
|
|
<!-- external links -->
|
|
|
|
<!-- end links -->
|
|
|
|
@reviewed 2022-02-28
|