Oskar Szura
Oskar Szura

Reputation: 2549

AngularJS application config file

It's just a conceptual question as I'm writing my first app in AngularJS.

Is it a good idea / practice to embed some 'app wide' / 'global', constants / configs variables within a Angurar's service? - as it is singleton by definition?

Upvotes: 0

Views: 100

Answers (1)

benek
benek

Reputation: 2178

Over than Angular app it is actually a good practice to externalize conf like parameters.

With Angular you can do it with "service" or "factory" functions. But the more appropriate is "constant" as it can be injected every where even in .config.

myApp.constant('CONF', function(){

  var YOUR_SERVER_CONSTANTS;

   // your declarations

  return YOUR_SERVER_CONSTANTS;

})

Upvotes: 1

Related Questions