I need to set application constants in my angular2 application , so that the things are available through out the entire application , in angular 1 i did with angular.constant and angular.value. I am looking for the best way here.
Asked
Active
Viewed 3,486 times
3
-
Possible duplicate of [Define global constants in Angular 2](http://stackoverflow.com/questions/34986922/define-global-constants-in-angular-2) – Estus Flask Oct 04 '16 at 05:51
-
see http://stackoverflow.com/a/38718878/2460760 – Nodarii Apr 07 '17 at 11:29
2 Answers
5
file constants.ts
export const XXX = 'yyy';
otherfile.ts
import {XXX} from 'constants.ts'

Günter Zöchbauer
- 623,577
- 216
- 2,003
- 1,567
3
If you want to encapsulate them in a variable:
export const BaseConstants = Object.freeze({
BASE_API_URL: 'http://example.com/'
});

bevrard
- 119
- 7