2

重构应用程序时出现以下错误:

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)

但我还没有发现任何循环依赖。还有什么可能是原因?

4

1 回答 1

0

它是由将自定义服务注入 ErrorHandler 引起的:

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

似乎只有 Angular 的服务(如 HttpClient)可以在那里注入。

于 2021-09-24T07:41:34.130 回答