Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define global constants in Angular 7 [duplicate]

Tags:

angular

I want to define global constant variable for my API url, which I want to access at many places.

In what type of file it will defined, and how to access them.

like image 716
Anand agrawal Avatar asked Aug 23 '26 02:08

Anand agrawal


1 Answers

Use the files environment.ts and environment.prod.ts (for production) to define all your global const and call them like this :

environment.ts

export const environment = {
  apiVersion: '1',
}

in other component or service

import { environment } from '../../environments/environment';

environment.apiVersion
like image 199
Abderrahim Soubai-Elidrisi Avatar answered Aug 25 '26 17:08

Abderrahim Soubai-Elidrisi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!