Is there any way to access environment variable in angular 2 components when using ng serve
?
E.g.:
API_URL=http://api.test.com ng serve
How can I access API_URL in Angular components?
Thanks in advance!
Is there any way to access environment variable in angular 2 components when using ng serve
?
E.g.:
API_URL=http://api.test.com ng serve
How can I access API_URL in Angular components?
Thanks in advance!
The CLI provides "environment" files just for that purpose. For development, put your configuration in the file:
src\environments.ts
For production, use the"
src\environments.prod.ts
When you build the application with:
ng build -prod
(or just ng build since -prod is the default)
Angular will use the environment.prod.ts file in place of the environment.ts file.