Where is the best place to define global variables?

Where is the best place to define global variables which can be used by all providers? The base URL of REST API (http://example.com/api/v1) is an example of such variables.

My guess is that I need a provider like DataProvider or GlobalProvider which stores and exposes global data to other providers and pages. I wonder if there is any better way to do this.

Sounds like a good plan to me.

1 Like

Don’t know if it’s the right way to do it, but I use a static for that purpose. In a separate file I’ve got something like:

export class Resources {
    static get Constants():any {
      return {
        API: {
           MY_URL: 'http://....'
         }
       }
    }
}

which I could then use like:

  Resources.Constants.API.MY_URL;
3 Likes