# Angular: NG0200: Circular dependency in DI detected for X

**Code:** `NG0200` · **Category:** Angular · **Seen on:** Angular, TypeScript

Two or more services inject each other (directly or through a chain), so Angular cannot create any of them first.

## 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_INTERCEPTOR` injecting a service that uses `HttpClient`

## Quick fix

1. Move the shared logic into a third service both depend on
2. Inject `Injector` and call `injector.get(X)` when needed
3. Break the interceptor cycle by injecting the `Injector` lazily

## Detailed fix by platform

### Angular

1. In an interceptor: `const auth = inject(Injector).get(AuthService);` inside the function to defer creation
2. Draw the dependency graph of the services named in the message

## Code examples

### Lazy injection to break a cycle

```typescript
@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

1. **Chain** — Which services are named in the message?
2. **Cycle** — Does A need B and B need A?
3. **Interceptor** — Does an interceptor inject something using HttpClient?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/angular/ng0200-circular-dependency-in-di)
