Niyaz
Niyaz

Reputation: 2893

Application constant in angular2?

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.

Upvotes: 3

Views: 3496

Answers (2)

bevrard
bevrard

Reputation: 119

If you want to encapsulate them in a variable:

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

Upvotes: 3

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657486

file constants.ts

export const XXX = 'yyy';

otherfile.ts

import {XXX} from 'constants.ts'

Upvotes: 5

Related Questions