gpt4 book ai didi

angular - 在定义 NgModule 时使用外部 JSON 文件的值

转载 作者:搜寻专家 更新时间:2023-10-30 21:47:30 24 4
gpt4 key购买 nike

目前,我正在使用一种非常常见的解决方案将 JSON 文件的内容加载到我可以注入(inject)到我的组件中的 Angular 5 应用程序中。这就像在此处的 Runtime configuration 节中描述的那样工作.

我正在使用一个需要在我的 app.module.ts 文件中初始化的 npm 包

@NgModule({
declarations: [
AppComponent
],
imports: [
/* .... */
[MsalModule.forRoot({
clientID: "...",
authority: "...",
redirectUri: <I need the value here from the JSON file>
})]
],
providers: [
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: (config: ConfigService) => () => config.load(),
deps: [ConfigService],
multi: true
}
]
bootstrap: [AppComponent]
})
export class AppModule { }

我使用 Angular-CLI,我知道我可以使用不同的环境文件,但 JSON 文件的内容在构建应用程序后可能会发生变化,我不能依赖它。

有没有办法在我需要的 NgModule 声明中立即使用来自 JSON 文件的值?

最佳答案

可以找到一个很好的替代品 herein this StackOverflow question

这种方式可以将 JSON 文件作为 JS 对象加载,我们可以在声明 NgModule 之前访问它。

关于angular - 在定义 NgModule 时使用外部 JSON 文件的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52284255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com