Storing application configuration settings

前端 未结 5 708
你的背包
你的背包 2021-01-31 07:39

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 cont

5条回答
  •  青春惊慌失措
    2021-01-31 08:19

    Define:

    angular.module('starter.config', [])
    .constant('appConfig', {
      'backend': 'http://localhost:3000/v1'
    });
    

    Usage:

    angular.module('starter.services', ['starter.config'])
    
    .factory('Locations', function(appConfig, $http) {
      return {
        all: function(successCb, errorCb) {
          $http.get(appConfig.backend + '/locations.json')
          .success(successCb)
          .error(errorCb);
        },
        get: function(locationId, successCb, errorCb) {
          $http.get(appConfig.backend + '/locations/'+ locationId +'.json')
          .success(successCb)
          .error(errorCb);
        }
      };
    })
    

提交回复
热议问题