NG0200: Circular dependency in DI detected for ApplicationRef

5.7k Views Asked by At

I got the following error while refactoring the app:

main.ts:21 Error: NG0200: Circular dependency in DI detected for ApplicationRef. Find more at https://angular.io/errors/NG0200
    at throwCyclicDependencyError (core.js:216)
    at R3Injector.hydrate (core.js:11433)
    at R3Injector.get (core.js:11256)
    at injectInjectorOnly (core.js:4751)
    at Module.ɵɵinject (core.js:4755)
    at Object.Config_Factory [as factory] (config.ts:7)
    at R3Injector.hydrate (core.js:11437)
    at R3Injector.get (core.js:11256)
    at injectInjectorOnly (core.js:4751)
    at Module.ɵɵinject (core.js:4755)

But I haven't found any circular dependencies. What else can be the cause?

1

There are 1 best solutions below

0
On BEST ANSWER

It was caused by injecting a custom service into ErrorHandler:

@Injectable()
export class GlobalErrorHandler extends ErrorHandler {
  /*constructor(protected readonly customService: CustomService) {
    super();
  }*/
}

Seems like only Angular's services (like HttpClient) can be injected there.