Jamie McCrindle
Jamie McCrindle

Reputation: 9214

How should I manage configuration for different environments in AngularJS

How should I manage different environment settings in AngularJS projects? For example, I'd like to configure things like this different depending on whether I'm in development, test, staging or production:

On the server side, in Django I'd use settings and local_settings or in Rails, I'd use different environment files like production.rb or development.rb. What's the best practice in AngularJS?

Upvotes: 1

Views: 1490

Answers (2)

phani
phani

Reputation: 1134

May be this lib https://www.npmjs.com/package/grunt-ng-constant could help u.

This question is related to How do I configure different environments in Angular.js?

Upvotes: 1

Guy Nesher
Guy Nesher

Reputation: 1385

The solution we use is rather straight forward. Django (or Flask in our case) passes a variable that contain all the api urls to the template where I transform it into a global javascript variable.

I then have a constant defined in Angularjs which fetches that variable. At this point all my services use that constant to retrieve the necessary api url.

Upvotes: 1

Related Questions