1

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:

  • Redirect URLs for single sign on
  • URLs for other services (especially those that support CORS or JSONP i.e. not on the same domain)

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?

Jamie McCrindle
  • 9,114
  • 6
  • 43
  • 48

2 Answers2

1

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.

Guy Nesher
  • 1,385
  • 2
  • 14
  • 26
1

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?

Community
  • 1
  • 1
phani
  • 1,134
  • 1
  • 11
  • 24