Use the Angular CLI Environment to Define Constants

Bram Borggreve
InstructorBram Borggreve
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 6 years ago

A default Angular application ships with two default environment files that can store constants that are different for each environment, one for development and the other for production.

We will define the apiUrl constant in both development and production environments.

The value for development is http://localhost:3000/api and the value for production is https://egghead-products-api.now.sh/api .

In angular.json we can find a configurations object where our production build is defined. We can see that in a production build, the environment.prod.ts will replace environment.ts.

Link to product api used in lessons

Instructor: [00:01] We open source environments/environments.ts and set the API URL property to our local development API. In the environmental prod.ts, we set the API URL to the production version of the API.

[00:16] In angular JSON in our project, we'll find a configuration object that defines our production builds. Inside there, we see that in the production builds, prod file will replace the other.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today