Skip to content

Instantly share code, notes, and snippets.

@cliffmeyers
Last active December 21, 2015 23: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 cliffmeyers/eba60914a543028c359f to your computer and use it in GitHub Desktop.
Save cliffmeyers/eba60914a543028c359f to your computer and use it in GitHub Desktop.
Get tasty donuts via a repository.
var donutModule = angular.module('donuts', []);
donutModule.service('donutRepository', ['$http', function($http) {
this.$http = $http;
/**
* Retrieves tasty donuts based on user requirements
*/
this.fetchDonuts = function(size, filling, glaze, hasHole) {
// construct url based on values bound to form elements
var url = '/api/donuts/list?size=' + size +
'&filling=' + filling +
'&glaze=' + glaze +
'&hole=' + hasHole ? 1 : 0;
// feed me
return this.$http.get(url)
.then(function(response) {
return response.data.results;
});
};
}]);
donutModule.controller('donutController',
['$scope', 'donutRepository', function($scope, donutRepository) {
// get in my belly
donutRepository.fetchDonuts($scope.size, $scope.filling, $scope.glaze, $scope.hasHole)
.then(function(donuts) {
$scope.donuts = donuts;
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment