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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With