Angular 角度4-最大调用堆栈core.js
我们正在开发一些应用程序,我们发现了非常严重的调用堆栈错误。 应用程序运行良好,但过了一段时间就会出现这种异常 我包括我的应用程序模块代码,我们声明了全球服务注入器,可能有问题。我还发现错误的路线会导致这种错误,但我想在发布之前等待任何答案 下面是在某些构造函数中使用此注入器的示例Angular 角度4-最大调用堆栈core.js,angular,typescript,Angular,Typescript,我们正在开发一些应用程序,我们发现了非常严重的调用堆栈错误。 应用程序运行良好,但过了一段时间就会出现这种异常 我包括我的应用程序模块代码,我们声明了全球服务注入器,可能有问题。我还发现错误的路线会导致这种错误,但我想在发布之前等待任何答案 下面是在某些构造函数中使用此注入器的示例 this.translateService = ServiceLocator.injector.get(TranslateService); 调用堆栈 defaultErrorLogger @ core.js:1
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();
};
}
调用堆栈超出错误通常意味着您正在调用一个调用自身的函数。这个错误没有说错误在哪里或什么地方,你必须自己找到它。不可能sherlock:D我知道,但是消息有一些信息,所以我想问:)你说你认为它来自路由或喷油器。我告诉你没有,你的代码出错了。尝试查找递归调用,为了简化它,我会亲自重置我的提交,直到我找到一个可以工作的项目版本,然后检查提交差异什么在进行递归调用。使用chrome调试器缩小代码范围并查找递归的内容(例如:在observable subscribe中,再次调用相同的函数).似乎是路线问题。你能分享一下你的路线代码吗?