Created
May 12, 2015 17:59
-
-
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.
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
// 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