| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
ย | ย | |||
ย | ย | |||
ย | ย | |||
ย | ย | |||
ย | ย | |||
ย | ย | |||
ย | ย | |||
ย | ย | |||
A complete example demonstrating how to inject environment variables into Angular applications at runtime using Docker, eliminating the need to rebuild your app for different environments.
Angular's default environment system bakes configuration values into JavaScript bundles during build time. This means:
This project demonstrates a Docker-based approach that:
# Clone the repository
git clone https://github.com/timothydodd/angular-dynamic-variables.git
cd angular-dynamic-variables
# Navigate to the Angular app directory
cd angular-dynamic-variables
# Install dependencies
npm install
# Run in development mode
ng serve
# Visit http://localhost:4200# Build the Docker image
docker build -t angular-dynamic-vars .
# Run with environment variables
docker run -p 8080:80 \
-e API_URL="https://api.production.com" \
-e FAV_COLOR="blue" \
-e FAV_CATCH_PHRASE="Hello Production!" \
angular-dynamic-vars
# Visit http://localhost:8080โโโ angular-dynamic-variables/ # Angular application directory โ โโโ src/ โ โ โโโ app/ โ โ โ โโโ _services/ โ โ โ โโโ config.service.ts # Configuration service โ โ โโโ environments/ โ โ โ โโโ environment.ts # Development config โ โ โ โโโ environment.prod.ts # Production config โ โ โโโ env-config.js # Runtime config file โ โโโ angular.json # Angular CLI configuration โ โโโ package.json # Dependencies โโโ env-config.template.js # Template with placeholders โโโ generate-env-config.sh # Startup script โโโ Dockerfile # Multi-stage Docker build
The following environment variables are supported:
| Variable | Description | Default |
|---|---|---|
| API_URL | Backend API URL | window.location.origin |
| FAV_COLOR | Theme color | 'yellow' |
| FAV_CATCH_PHRASE | Application tagline | 'I like producing' |
myNewVar: '${MY_NEW_VAR}',ENV_VARS="API_URL FAV_COLOR FAV_CATCH_PHRASE MY_NEW_VAR"get myNewVar(): string {
return this.config.myNewVar;
}version: '3.8'
services:
frontend:
build: .
ports:
- "8080:80"
environment:
- API_URL=https://api.example.com
- FAV_COLOR=green
- FAV_CATCH_PHRASE=Docker Compose Rocks!This repository accompanies the blog post: "Dynamic Environment Variables in Angular: A Docker-Ready Solution"
Read the full tutorial here โ
This project is licensed under the MIT License
If this project helped you, please give it a โญ on GitHub!
Making Angular deployments more flexible, one container at a time! ๐ข
| Back | FazBrowse Home | New Git URL |