2

With Angular2 you can use src/environments/environment.ts and *.prod.ts to configure either production or development environments. Now we have a huge staging requirements and we will need e.g. 5-10 API Urls. How to set and read environment variables other than --prod or --dev with angular-cli, e.g. URL="http://server12a"?

1 Answer 1

3

You can have all different kind of environments. Define each of those in your angular-cli.json file:

  "environments": {
    "local": "environments/environment.ts",
    "test": "environments/environment.test.ts",
    "staging ": "environments/environment.staging.ts",
    "prod": "environments/environment.prod.ts"
  }

Within these files you can have something along the lines of:

export const environment = {
  URL="http://server12a"
};

When you build you have to specify the right environment like:

ng build --env=staging
Sign up to request clarification or add additional context in comments.

Comments

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.