angular - 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();
};
}
解决方案
推荐阅读
- javascript - LEAFLETJS 获取航路点之间路线上的所有点
- javascript - JS中的递归计数达到0后会发生什么?
- kubernetes - 在 Kubernetes 上构建服务
- android - 如何在 Firestore 中读取嵌套数组和映射?
- azure - Kubernetes cert-manager withletsencrypt 等待证书颁发
- events - 过滤掉重复项,仅在发生更改时生成事件
- regex - 用于排除具有特定模式的文件的正则表达式
- c++ - 为什么 lldb 漂亮的打印机不适用于 MacOS 上的 GNU GCC 编译程序?
- node.js - 了解 Flutter、NodeJS 和 Cloud Functions 中的 JSON 转换。面临代码中的主要问题
- react-native - useState 不是 useEffect 中的函数