3

I have a problem which I know has solutions but I am not sure how to implement it. I have a file that reads a server URL in src folder. But depending on the environment configuration, I need to read the server URL from the root folder into the TypeScript file in src folder. How can it be done?

Currently in my TypeScript file, I have this line:

export const ServerURL = <serverURL>;

I am importing this file into other components which use the server URL.

import { ServerURL } from '../file-path';

Now I need to read this ServerURL from a config file in the root of this application. Do we use a separate JavaScript or JSON file to read the server URL or can it be done in the systemjs.config.js file which is one of the main files of the application? Any advice would be great!

dakab
  • 5,379
  • 9
  • 43
  • 67
Mitchell Y
  • 113
  • 3
  • 14
  • check this answer http://stackoverflow.com/questions/42110817/load-config-json-file-in-angular-2/42111501#42111501 – dev_in_progress Feb 23 '17 at 10:15
  • The answer isn't clear enough for my understanding, unfortunately. Is there a better way to do this? – Mitchell Y Feb 23 '17 at 10:43
  • just a note - `@angular/cli` projects come built with this. if you `npm install @angular/cli -g` and generate a project with `ng new [project-name]` there is an environments config folder which defers to arbitrary different config files at build time based on the flag `--env=[envName]` – William B Feb 23 '17 at 18:06
  • I've provided answer [here](https://stackoverflow.com/posts/47110796/edit) – Karlen Nov 04 '17 at 12:46

0 Answers0