-1

I am looking for a better way to store my static and dynamic global variables in my application using angularjs providers.

I have gone through this angularjs documentation for providers but it lacks the detailed explanation. I am currently building an application which require static and dynamic sets of global variables which we are planning to use through out our application.

Below are some of those static variables to make things clear.

dateFormat: 'MM/dd/yyyy',
momentDateFromat: 'MM/DD/YYYY',
secondDateFormat: 'MMM d, y',
monthYearDateFormat: 'MMM y',
shortDateTimeFormat: 'short',
mediumDateTimeFormat: 'medium',
inputDebounce: 1000,
searchSymbolsStart: 3,
isDebugLogEnabled: false,
fractionSize: 0,
secondFractionSize: 2,
markerThreshold: 31, 
startSelectableDate: startSelectableDate,
endSelectableDate: endSelectableDate
and many more

The dynamic set of global variables are more depends on the customer selection at early stage and are changeable. Below are some of those dynamic variables.

Logged in user details(JSON object)
Customes tree
Selected Customer(User can change this from tree)
Competitors(Competitors of selected customer)
and many more

I have also gona through this stack overflow thread but cant make my choice of which way to go.

My question is more in terms of architecture.

Community
  • 1
  • 1
J-D
  • 1,575
  • 1
  • 11
  • 22
  • What is the specific question? – charlietfl Nov 05 '15 at 13:45
  • Have a look at the first statement of my question "I am looking for a better way to store my static and dynamic global variables" and the last line "My question is more in terms of architecture.". So basically i am confused between Value, Factory, Service , Constant and Provider. I am looking for best practices to store this variables. – J-D Nov 05 '15 at 18:08
  • 1
    try this http://stackoverflow.com/questions/15666048/angularjs-service-vs-provider-vs-factory/15666049#15666049 ... `better` is dependent on your needs. Try one and if you need to change it's not a huge deal – charlietfl Nov 05 '15 at 18:22

1 Answers1

1

You can use constants for the static ones, and a service for the dynamic ones. Don't worry about factory or service, just go with service as with Angular 2 the whole difference will be gone and will resemble services mostly. It's a syntactic thing anyway, and not important at all.

Maarten
  • 4,643
  • 7
  • 37
  • 51