我正在尝试在文件上加载初始配置,以将以下内容加载到app.module.ts
let myConfig = undefined;
export function initializeMyApp(nmyService : MyConfigService ) {
return (): Promise<any> => nmyService.loadConfig()
.toPromise()
.then( config => {
myConfig = config;
})
}
imports: [MsalModule.forRoot({ clientID = myConfig.clientID etc... })
providers: [
{
provide: APP_INITIALIZER,
useFactory: initializeMyApp,
deps: [MyConfigService],
multi: true
},
]
启动应用程序时,出现以下错误
> Error: StaticInjectorError(AppModule)[InjectionToken Application
> Initializer -> MyConfigService]: main.ts:12 Failed to load resource:
> the server responded with a status of 404 (Not Found)
> [https://localhost:4200/site.json] Manifest: Line: 1, column: 1,
> Unexpected token. [https://localhost:4200/site.json]
有什么主意吗?谢谢。
答案 0 :(得分:0)
检查您的MyConfigService
服务。您是否正在使用HttpClient
(例如Http
)依赖项注入?
如果是这样,则将HttpClientModule
导入模块(在“导入”部分)。