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
  • 623,577
  • 216
  • 2,003
  • 1,567
Niyaz
  • 2,677
  • 3
  • 21
  • 40

2 Answers2

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