填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

NG0200: Circular dependency in DI detected while instantiating a provider
DI 在实例化服务提供者时检测到循环依赖

说明

Description

当某个服务的依赖项直接或间接依赖于此服务本身时,便存在循环依赖项。例如,如果 UserService 依赖于 EmployeeService ,而 EmployeeService 也依赖于 UserService。 Angular 将不得不先实例化 EmployeeService 再创建 UserService,而 EmployeeService 又依赖于 UserService 本身。

A cyclic dependency exists when a dependency of a service 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 the error

使用调用栈来确定循环依赖项存在的位置。通过源码映射找出组件、模块或服务的依赖项,并找出导致此问题的循环,你将能够查看是否有任何子依赖项依赖于原始文件。

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 the component, module, or service’s dependencies and identify 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.