import { Injectable } from "@angular/core" ; import { IAppConfig } from "./app-config.model" ; import { HttpClient } from "@angular/common/http" ; example @ Injectable ( ) export class AppConfig { /** settings for the app */ static settings : IAppConfig ; /** file location of the config file to be created by the administrator */ private readonly CONFIG_FILE = "assets/config.json" ; /** fallback file location of the config that is part of the project already if the "real" config file isn't found */ private readonly DEFAULT_CONFIG_FILE = "assets/config.default.json" ; constructor ( private http ) { } /**
     * Load the config file into the `AppConfig.settings` so they can be used synchronously anywhere in the code after that.
     *
     * If the config file does not exist, uses the default config as a fallback.
     */ load ( ) { return this . loadAppConfigJson ( this . CONFIG_FILE ) . then ( ( result ) => result , ( ) => this . loadAppConfigJson ( this . DEFAULT_CONFIG_FILE ) ) ; } param jsonFileLocation private loadAppConfigJson ( jsonFileLocation ) { return new Promise < void > ( ( resolve , reject ) => { this . http . get < IAppConfig > ( jsonFileLocation ) . toPromise ( ) . then ( ( result ) => { AppConfig . settings = result ; resolve ( ) ; } ) . catch ( ( response ) => { reject ( $localize `Could not load file '${ jsonFileLocation }': ${ JSON . stringify ( response ) }` ) ; } ) ; } ) ; } }