title: Best way to save and use config settings in AngularJS
body: <p>I'm new to AngularJS and just building an app to learn it. My app calls a REST API and right now I have the hostname hard coded in the app.  I want to make this in app setting (and maybe later have somewhere to configure it). I thought I'd start with a constant. Should it go in my app.js like this? If so, I'm not sure of the syntax for adding it to the .config settings with $routeProvider there too</p>
  
  <pre><code> (function () {
  
          // Define module and add dependencies inside []
          var app = angular.module("haClient", ["ngRoute"]);
  
          app.constant('hostname', 'http://192.192.192.192:8176');
  
          app.config(function ($routeProvider) {
              $routeProvider
                  // Register routes
                  // Main route
                  .when("/main", {
                      templateUrl: "main.html",
                      controller: "MainController"//,
                      //activeTab: 'home'
                  })
                  // Device List 
                  .when("/devices", {
                      templateUrl: "devicelist.html",
                      controller: "DeviceListController"
                  })
                  // Device details (param is device name)
                  .when("/device/:devicename", {
                      templateUrl: "device.html",
                      controller: "DeviceController"
                  })
                  // Invalid URL's get sent back to main route
                  .otherwise({ redirectTo: "/main" });
          }); // End App Config
  
      }());
  </code></pre>
  
  <p>This is the module that needs to use it (called from controllers):</p>
  
  <pre><code>(function () {
  
      var deviceCtrl = function ($http) {
          var getDevices = function () {
              return $http.get("http://192.192.192.192:8176/devices.json/")
                            .then(function (response) {
                                return response.data;
                            });
          };
  
          // get details and return a promise
          var getDeviceDetails = function (deviceName) {
              return $http.get("http://192.192.192.192:8176/devices/" + deviceName + ".json/")
                            .then(function (response) {
                                return response.data;
                            });
          };
  
  
          // Public API
          return {
              getDeviceDetails: getDeviceDetails,
              getDevices: getDevices
      };
      };
  
      var module = angular.module("haClient");
  
  }());
  </code></pre>
  
  <p>Can someone enlighten em on the best way to set it and get it?</p>
  
  <p>Thanks</p>