-1

In my Angular 2 project I currently have an object called translation that contains a couple of strings that I use in some forms, it globally looks as follows:

    public translator = {
        'performance_standard_time_deviation': {
            'both': 'Sentance A',
            'shorter': 'Sentance B',
            'longer': 'Sentance C',
            'no': 'Sentance D'
        },
        'performance_soundcheck': {
            2: 'Sentance A',
            1: 'Sentance B',
            0: 'Sentance C'
        }
};

I need this object in a couple of components, currently I just copied the code and pasted it in each component, this obviously isn't a good solution since it violates the DRY rule. My question is as follows, what is the correct solution to share objects like these in an Angular 2 project? I know that you are able to pass variables from component to component, but that is a bit devious. What is the preferred way?

hY8vVpf3tyR57Xib
  • 3,574
  • 8
  • 41
  • 86

1 Answers1

0

try this:

export const YOUR_CONSTANT = {};

Put this in a separate file where you have all your constants like constants.ts and export it into the files that need it.

Som
  • 460
  • 1
  • 5
  • 11