填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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.