是否有一种动态方法可以在运行时在 Angular 中设置或包含 StoreDevtoolsModule?或者,是否有一种方法可以在导入 app.module 之前加载 JSON 文件?
我想在生产中隐藏 Redux DevTools。现在我使用 config.json 覆盖应用程序中的变量,并且我不想为此使用environment.ts。
我想知道是否可以在加载导入之前加载config.json。
您需要在引导发生之前加载配置:
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { createAppConfig } from './app/app.config';
// 👇 this can also be an endpoint
// (just make sure that the endpoint is publically available, also for anonymous users)
fetch('./assets/environment-config.json')
.then((resp) => resp.json())
.then((config) => {
bootstrapApplication(AppComponent, createAppConfig(config));
});
有关更多信息,请参阅我的博客 https://timdeschryver.dev/blog/angular-build-once-deploy-to-multiple-environments 或独立 API 的版本 https://timdeschryver.dev/blog /多个版本使用相同但可配置的角度独立应用程序构建