I would like to create a service that will create an interface to AngularJS's $http
based on this. I would like to use dependency injection to inject the service without re-writing individual function calls and keeping the code clean. To do this I am providing a common service that creates a variable to the $http object like this:
commonService = function(...) {
return {
...
$http: $http
}
Then I use common.$http
everywhere in the code. To change $http from AngularJS $http to my httpService, I need to only change it in one place. httpService looks like this:
function httpService($http, $q, pendingRequests, $interval) {
var get = function(url) {
...
return requestPromise;
};
var service = {
get:get
};
return service;
}
This works for calls to $http.get()
but what about calls to $http({method:'get', url:'...'});
?
Is it possible to provide the () method, which is really httpService()()? Otherwise it would call the AngularJs method httpService().