This is a good use case for provider api. You can define your api using the module.provider
. Define a provider for your server configuration, something like
module.provider('serverConfig',function() {
var serverUrl='val'; //default url
this.setServerUrl=function(url) {
serverUrl=url;
};
this.$get=[function(){
return {url:serverUrl};
}];
})
Once you define such a config service, use it in each of your own services like
factory('UserService', function($resource,serverConfig) {
return function(whatsonUserId) {
return $resource(serverConfig.url+'/rest/user/:action');
}
The provider needs to be configured at the config stage
myApp.config(["serverConfigProvider", function(serverConfigProvider) {
serverConfigProvider.setServerUrl('serverUrlstring');
}]);