Angular: NG0200: Circular dependency in DI detected for X
Two or more services inject each other (directly or through a chain), so Angular cannot create any of them first.
NG0200: Circular dependency in DI detected forCircular dependency in DI detectedcyclic dependencyCannot instantiate cyclic dependency Meaning
The injector builds a service by first building its dependencies. If A needs B and B needs A, it loops. Break the cycle by extracting shared logic into a third service, injecting lazily with Injector.get, or using events instead of direct references.
Common causes
- Service A and service B inject each other
- A longer cycle through three or more services
- A token provided in a component that also injects the parent
- Barrel file import order hiding a cycle
- An
HTTP_INTERCEPTORinjecting a service that usesHttpClient
⚡ Quick fix
- Move the shared logic into a third service both depend on
- Inject
Injectorand callinjector.get(X)when needed - Break the interceptor cycle by injecting the
Injectorlazily
Detailed fix by platform
Angular
- In an interceptor:
const auth = inject(Injector).get(AuthService);inside the function to defer creation - Draw the dependency graph of the services named in the message
Code examples
Lazy injection to break a cycle
@Injectable({ providedIn: 'root' })
export class AuthInterceptorService {
private injector = inject(Injector);
token() { return this.injector.get(AuthService).token; } // resolved when called, not at construction
}How to diagnose
- Chain — Which services are named in the message?
- Cycle — Does A need B and B need A?
- Interceptor — Does an interceptor inject something using HttpClient?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- exceeded maximum budget Angular build: Error: bundle initial exceeded maximum budget. Budget 1.00 MB was not met by 120.00 kB with a total of 1.12 MB
- NG0201 Angular: NG0201: No provider for X found in NodeInjector
- NG0203 Angular: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer or a function used with runInInjectionContext
Most viewed in Angular
- NG0100 Angular: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked
- NG8002 Angular: NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'
- Cannot GET /route on refresh Angular (production): Cannot GET /dashboard — 404 when refreshing or opening a deep link
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026