maddie
maddie

Reputation: 629

Design pattern for sitewide configuration in Angular JS

I want to set some user preferences in my angular app. I will get these preference from a REST api so I will need to make a http call. Once these have been fetched from the API, their values will not be modified.

What is the best practice in this case?

Can I make http calls in angular.module.value? Or use something like a provider? Or just write a service? What are the things to consider in any of these approaches?

What is the design pattern to be followed in this case?

Upvotes: 0

Views: 36

Answers (1)

Chris Halcrow
Chris Halcrow

Reputation: 32050

You could create a service using the factory recipe. That will make the code a lttle cleaner and more modular.

Following that, you could put the user preferences on the $rootScope. This is a good case for a valid use of $rootScope, since your values are constants with application-wide applicability.

Upvotes: 1

Related Questions