Angular 4-最大调用堆栈core.js

时间:2018-09-04 10:47:41

标签: angular typescript

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

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

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

 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(); 
  };
}

0 个答案:

没有答案