首页 > 解决方案 > Angular 4 - 最大调用堆栈 core.js

问题描述

我们正在开发一些应用程序,我们发现了非常讨厌的调用堆栈错误。应用程序运行良好,但一段时间后出现此异常。

我包含了我的应用程序模块代码,我们声明了全局服务注入器,也许有问题。我还发现错误路线可能导致这种错误的信息,但我想在发布它们之前等待任何答案。

这是在某些构造函数中使用此注入器的示例

 this.translateService = ServiceLocator.injector.get(TranslateService);

调用栈

defaultErrorLogger @ core.js:1671ERROR RangeError: StaticInjectorError(AppModule)[LocationStrategy -> PlatformLocation]:
 StaticInjectorError(Platform: core)[LocationStrategy -> PlatformLocation]:
   Maximum call stack size exceeded
   at resolveToken (core.js:1294)
   at tryResolveToken (core.js:1242)
   at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1139)
   at resolveToken (core.js:1298)
   at tryResolveToken (core.js:1242)

应用模块

  @NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    AppRoutingModule,
    HttpClientModule,
    BrowserModule,
    BrowserAnimationsModule,
    CoreModule,
    ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }),
  ],
  providers: [
    AppConfigService,
    { provide: APP_INITIALIZER, useFactory: loadConfigService , deps: [AppConfigService], multi: true },
    httpInterceptorProviders,
  ],
  bootstrap: [AppComponent],
})
export class AppModule {
  constructor(private injector: Injector) {    // Create global Service Injector.
    ServiceLocator.injector = this.injector;
} 
}

export function loadConfigService(configService: AppConfigService): Function {
  return () => { 
    return configService.load(); 
  };
}

标签: angulartypescript

解决方案


推荐阅读