Skip to content

Instantly share code, notes, and snippets.

@alatzl
Created May 12, 2015 17:59
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/ee9837bfe8464c7873d2 to your computer and use it in GitHub Desktop.
Save alatzl/ee9837bfe8464c7873d2 to your computer and use it in GitHub Desktop.
Two services that do almost the same thing; we can abstract out the repetition.
// An example showing two services that are nearly identical
angular.module('petStoreApp', [])
.service('catService', function($http) {
var svc = {
getList: function() { // get a list of all cats
$http({ method: 'GET', url: 'cats/all' })
.then(successFn, errorFn);
},
getInfo: function(catId) { // get info about a specific cat
$http({ method: 'GET', url: 'cats/' + catId })
.then(successFn, errorFn)
}
};
return svc;
})
.service('dogService', function($http) {
var svc = {
getList: function() { // get a list of all dogs
$http({ method: 'GET', url: 'dogs/all' })
.then(successFn, errorFn);
},
getInfo: function(dogId) { // get info about a specific dog
$http({ method: 'GET', url: 'dogs/' + dogId })
.then(successFn, errorFn);
}
};
return svc;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment