0

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 ?

0

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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) {

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.