Компиляция AOT не позволяет использовать нестатически анализируемые значения в Angular декораторах.
Существует несколько вариантов. Вот тот, который ждет конфигурации от сервера, прежде чем приступить к обновлению приложения.
// main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { configurationToken } from './app/configuration';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
// Platform creation and bootstrapping of the application is delayed
// until we have loaded the configuration file.
fetch('/assets/configuration.json')
.then(configuration =>
platformBrowserDynamic([
{ provide: configurationToken, useValue: configuration },
]).bootstrapModule(AppModule))
.catch(error => console.error(error));
// configuration.ts
import { InjectionToken } from '@angular/core';
// We create an interface for the configuration JSON object
export interface Configuration {
readonly apiUrl: string;
readonly timezone: string;
readonly websocketUrl: string;
}
// We use a dependency injection token to access the configuration
// in our application.
export const configurationToken = new InjectionToken('Configuration');
// time.service.ts
import { Inject, Injectable } from '@angular/core';
import { Configuration, configurationToken } from './configuration';
@Injectable()
export class TimeService {
constructor(
@Inject(configurationToken) private configuration: Configuration,
) {}
// Configuration is available synchronously since it's just an object
// that can be injected.
get timezone(): string {
return this.configuration.timezone;
}
}
Дополнительные параметры в " Обработка Angular сред при непрерывной доставке " Кевин Кройцер.