我正在实现应用程序初始化程序,我遇到了如下循环依赖错误
未捕获的错误:提供程序解析错误:无法实例化循环依赖!ApplicationRef ("[ERROR ->]"): 在 NgModule AppModule 中的 ./AppModule@-1:-1 在 NgModuleProviderAnalyzer.push../node_modules/@angular/compiler/fesm5/compiler.js.NgModuleProviderAnalyzer.parse (compiler. js:11472) 在 NgModuleCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.NgModuleCompiler.compile (compiler.js:11836) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/ compiler.js.JitCompiler._compileModule (compiler.js:23882) 在 compiler.js:23841 在 Object.then (compiler.js:1007) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js .JitCompiler._compileModuleAndComponents (compiler.js:23839) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler。 webpack_require @ bootstrap:81 0 @ main.ts:12 webpack_require @ bootstrap:81 checkDeferredModules @ bootstrap:43 webpackJsonpCallback @ bootstrap:30 (匿名) @ main.js:1
这就是我的初始化程序的样子
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
@Injectable()
export class InitializerService {
flag = false;
constructor(private http: HttpClient, private route: ActivatedRoute) { }
initialize(): boolean {
// access query params using ActivatedRoute object
// some http calls using HttpClient object
// also use objects of HttpHeaders and HttpParams
return this.flag;
}
}
以下是我在 NgModule 中提供服务的方式
providers: [
InitializerService,
{ provide: APP_INITIALIZER, useFactory: init_app, deps: [InitializerService], multi: true},
{ provide: HTTP_INTERCEPTORS, useClass: Interceptor, multi: true }
],
我不确定为什么会看到循环依赖错误