Created
May 12, 2015 18:11
-
-
Save alatzl/0d8ee1acc0616ad09598 to your computer and use it in GitHub Desktop.
Create a base service and extend for each specific use case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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