-
-
Save cliffmeyers/eba60914a543028c359f to your computer and use it in GitHub Desktop.
Get tasty donuts via a repository.
This file contains 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
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