分析错误:应用程序初始化程序中存在循环依赖项



我正在实现应用程序初始值设定项,我遇到了如下所示的循环依赖性错误

未捕获错误:提供程序解析错误:无法实例化循环依赖项!ApplicationRef("[ERROR->]"):在中的NgModule AppModule中/AppModule@-1:-1在NgModuleProviderAnalyzer.push../node_modules/@angular/compiler/fesm5/compiler.js.NgModuleProvierAnalyzer.parse(compiler.js:11472)在NgModuleCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.NgModuleCompiller.compile(编译器.js:11836)在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitComplier._compileModule(compiler.js:23882)在compiler.js:23841在Object.then(compiler.js:1007)在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitComplier._compileModuleAndComponents(compiler.js:23839)在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompler.compileModuleAsync(compiler.js:23799)在CompilerImpl.push../node_modules/@angular/platform browser dynamic/fem5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync(平台浏览器动态.js:143)在PlatformRef.prush../node_modules/@angular/core/fism5/core.js.PlatformRef.bootstrapModule(core.js:4352)在对象/src/main.ts(main.ts:11)推动/node_modules/@angular/compiler/fesm5/compiler.js.NgModuleProviderAnalyzer.parse@compiler.js:11472推动/node_modules/@angular/compiler/fesm5/compiler.js.NgModuleCompiler.compile@compiler.js:11836推动/node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModule@compiler.js:23882(匿名)@compiler.js:23841然后@compiler.js:1007推动/node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents@compiler.js:23839推动/node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.com.pileModuleAsync@compiler.js:23799推动/node_modules/@angular/平台浏览器动态/fem5/platform-browser-dynamic.js.CompileImpl.compileModuleAsync@平台浏览器动态.js:143推动/node_modules/@angular/core/fism5/core.js.PlatformRef.bootstrapModule@core.js:4352./src/main.ts@main.ts:11webpack_require@bootstrap:810@main.ts:12webpack_require@bootstrap:81checkDeferredModules@bootstrap:43webpackJsonpCallback@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 }
],

我不确定为什么我看到循环依赖性错误

由于引导,ActivatedRoute在APP_INITIALIZER不可用。您可以使用APP_BOOTSTRAP_LISTENER InjectionToken来确保ActivatedRoute可用(在引导完成后发生)。

相关内容

  • 没有找到相关文章

最新更新