Created
August 21, 2018 06:15
-
-
Save joostme/8ca7b7470320e5febd56dfac60619553 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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