Skip to content

Instantly share code, notes, and snippets.

@cliffmeyers
Created August 30, 2013 06:13
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/534c3326952498a65ee4 to your computer and use it in GitHub Desktop.
Save cliffmeyers/534c3326952498a65ee4 to your computer and use it in GitHub Desktop.
Mock repository implementation using in memory data with $q/$timeout
var donutModule = angular.module('donuts', []);
donutModule.service('donutRepository', ['$q', '$timeout', function($q, $timeout) {
// get some donuts based on user requirements
this.fetchDonuts(size, filling, glaze, hasHole) {
var deferred = $q.defer();
// return abitrary data after 500ms delay to simulate server call
$timeout(function() {
// sorry bro, we're sold out
deferred.resolve([]);
}, 500);
return deferred.promise;
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment