Global Constants

Hey guys,

where would you save global constants, that needs to be used from every point in the application? I would not like to put those values inside the file… Any other idea?


Are you using Angular? If so, then I’d use a provider for that - if the constants you are referring to are not environment related.

1 Like

Got an example for a provider of constant values?

Are you using angular?

This is what I would do:

import { Injectable } from '@angular/core';

  providedIn: 'root',
export class UserService {

 giveMyStaticData(paramName:string) {
          // based on hashtable return the data in cloned way ...


And have a getter method giving the data to whoever needs it - ideally via Observable pattern or as a clone to avoid other parts changing content of objects - an unexpected side-effect of working with javascript.

But I would really just like to export variables (as constants) - would a provider not be a little bit of overhead?

Fair point… of course also pending where you get your constants from if retrieved dynamically…


I reckon you know that constants strictly spoken don’t exists in javascript - no runtime checks on code changing the content.