Skip to content

Instantly share code, notes, and snippets.

@alatzl
Created May 12, 2015 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alatzl/0d8ee1acc0616ad09598 to your computer and use it in GitHub Desktop.
Save alatzl/0d8ee1acc0616ad09598 to your computer and use it in GitHub Desktop.
Create a base service and extend for each specific use case.
// Base service
angular.module('petStoreApp', [])
.service('petService', function($http) {
var petSvc = function(_endpoint_) {
var endpoint = _endpoint_ + '/';
return {
getList: getList,
getInfo: getInfo
};
function getList() {
$http({ method: 'GET', url: endpoint + 'all' })
.then(successFn, errorFn);
}
function getInfo(petId) {
$http({ method: 'GET', url: endpoint + petId })
.then(successFn, errorFn)
}
};
return petSvc;
})
// Now our cat and dog services can extend the base service
.service('catService', funciton(petService) {
var catSvc = petService('/cats');
return catSvc;
})
.service('dogService', function(petService) {
var dogSvc = petService('/dogs');
return dogSvc;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment