Here is my typical service definition:
home = angular.module('home');
home.factory("homeService", function ($http, $q) {
var service =
{
geCurrentSummary: function ()
{
var deferred = $q.defer();
var response = $http({
method: "post",
crossDomain: true,
dataType: "json",
withCredentials: true,
data: "{}",
headers: {
'Content-Type': "application/json",
"Accept": "application/json"
},
url: "someURL",
});
response.success(function (data) {
deferred.resolve(data);
});
response.error(function (data) {
alert('Error');
});
// Return the promise to the controller
return deferred.promise;
},
return service;
});
And in controller:
home.controller('homeController', function($scope, homeService) {
......
homeService.getCurrentSummary().then(callBack);
.......
Everything works fine. When I need to create another call to the server I
copy and paste the above code, change function name and change url
property.
But now, when I have a stable code I would like to use a proper way of
reusing http service code. What would an inheritance pattern be to have a
base service class and then reuse it in every http call?
Thanks
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.