Skip to content

Instantly share code, notes, and snippets.

@whisher
Created July 30, 2013 13:25
Show Gist options
  • Save whisher/6112865 to your computer and use it in GitHub Desktop.
Save whisher/6112865 to your computer and use it in GitHub Desktop.
//services.js
services.factory('RecipeLoader',function(Recipe, $route, $q) {
return function() {
var delay = $q.defer();
Recipe.query({id: $route.current.params.recipeId}, function(recipe) {
delay.resolve(recipe);
}, function() {
delay.reject('Unable to fetch recipe ' + $route.current.params.recipeId);
});
return delay.promise;
};
});
//controllers.js
app.controller('ViewCtrl',function($scope, $location, recipe) {
$scope.recipe = recipe[0];
$scope.edit = function() {
$location.path('./edit/' + recipe.id);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment