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!

4
  • check this answer stackoverflow.com/questions/42110817/… Commented Feb 23, 2017 at 10:15
  • The answer isn't clear enough for my understanding, unfortunately. Is there a better way to do this? Commented Feb 23, 2017 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] Commented Feb 23, 2017 at 18:06
  • I've provided answer here Commented Nov 4, 2017 at 12:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.