3

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.

Günter Zöchbauer
  • 558,509
  • 191
  • 1,911
  • 1,506
Niyaz
  • 2,437
  • 3
  • 19
  • 38

2 Answers2

5

file constants.ts

export const XXX = 'yyy';

otherfile.ts

import {XXX} from 'constants.ts'
Günter Zöchbauer
  • 558,509
  • 191
  • 1,911
  • 1,506
3

If you want to encapsulate them in a variable:

export const BaseConstants = Object.freeze({
  BASE_API_URL: 'http://example.com/'
});
bevrard
  • 119
  • 7