2

In my angular 4 project I have a made a file of some constants and getting access to it I am importing that file to my services file and can access the variables, but the problem is in each and every services I have to import that file.

Is there any process so that I can load my constant file in one place and can use that file variables throughout the module not importing it each and every time.

Thank you.

Sandip Nag
  • 968
  • 2
  • 18
  • 34
  • Can you post your code? You can export it as a single variable instead of multiple files so that you will only import one file for any variable. – Bk Santiago May 18 '18 at 02:18

1 Answers1

1

Simple answer is NO. But you can export as a single variable and access it as,

You can do something like this:

In your config.ts:

export const Keys = {
    CONFIG_1: 'VALUE',
    CONFIG_2: 'VALUE'
};

Then in the file that you importing it you can do below:

import { Keys } from './config';
Keys.CONFIG_1 //return the value 'value'

You should always import the file. But if you still wanna do that you can do it in the ugliest way like this:

window.globalvar = "myapi"

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396