Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

For example, I have this call:

$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
  // this callback will be called asynchronously
  // when the response is available
}).
error(function(data, status, headers, config) {
  // called asynchronously if an error occurs
  // or server returns response with an error status.
});

I need it to request http://my-api-url.com/someUrl, but I don't want to type it everywhere because it will change in the future.

How can I configure it globally ?

share|improve this question
up vote 3 down vote accepted

Use a constant:

var myApp = angular.module('myApp',[]);

myApp.constant('myUrls', {
    someUrl: 'http://my-api-url.com/someUrl,',
});

mayApp.directive('myDirective', ['myUrls', function (myUrls) {
    return {
        ....
        // use myUrls.someUrl
        ....
    };
}]);

AngularJS Module

share|improve this answer

i don't think you can, that would cripple any other call to other url so what you could do is setting a host variable in a service pointing to the host you want and then in every call set your url as.

$http.get(service.host+'/somePath'}).
success(function(data, status, headers, config) {

}).
error(function(data, status, headers, config) {

});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.