Skip to content

Instantly share code, notes, and snippets.

@joostme
Created August 21, 2018 06:15
Show Gist options
  • Save joostme/8ca7b7470320e5febd56dfac60619553 to your computer and use it in GitHub Desktop.
Save joostme/8ca7b7470320e5febd56dfac60619553 to your computer and use it in GitHub Desktop.
main.ts
-------
loadEnvironment(environment.environmentUrl)
.then(env => {
if (env.production) {
enableProdMode();
}
bootstrap();
});
load-environment.ts
-------------------
export function loadEnvironment(url: string): Promise<any> {
return fetch(url)
.then(response => response.json())
.then(env => {
window['__env__'] = env;
return env;
});
}
environment-factory.ts
----------------------
export function getEnvironmentFactory(): any {
return window['__env__'];
}
environment.module.ts
---------------------
export const ENVIRONMENT_CONFIG = new InjectionToken('environmentConfig');
@NgModule({
providers: [
{
provide: ENVIRONMENT_CONFIG,
useFactory: getEnvironmentFactory
}
]
})
export class EnvironmentModule {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment