Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing application configuration settings

What is the best place to store application configuration settings in AngularJS? This could be things like application constants, lookups etc. which could be used both from controllers and services or factories. I could create a separate service that stores and retrieves these things but I was wondering if there is another proper place to store and retrieve those.

like image 613
govin Avatar asked Jul 03 '13 19:07

govin


People also ask

What can be used to store configuration settings of an application?

In a Microsoft Azure hosted application, a possible choice for storing configuration information externally is to use Azure Storage.

Should I store configuration in database?

It really depends on your application. Storing the settings in the database has several advantages: Security - users can easily alter settings in the file or overwrite the contents. For Distribution - the same settings can be updated and loaded onto any machines on the network.


1 Answers

You can use the constant() provider!

app.constant('myAppConfig', {ver: '1.2.2', bananas: 6, hammocks: 3, bananaHammocks: true}); 

This is not a whole lot different from Terry's solution, but constants don't change so they are applied before the other providers. Also, this module can be injected into your config function.

app.config(function(myAppConfig){     console.log(myAppConfig.bananaHammocks); }); 

have fun

like image 177
Hippocrates Avatar answered Oct 05 '22 10:10

Hippocrates