Reputation: 1861
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 ?
Upvotes: 0
Views: 1759
Reputation: 12813
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
....
};
}]);
Upvotes: 3
Reputation: 5435
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) {
});
Upvotes: 0