Skip to content

Instantly share code, notes, and snippets.

@gsans
Last active April 17, 2016 04:57
Show Gist options
  • Save gsans/2587aa2d2d194ff2b966 to your computer and use it in GitHub Desktop.
Save gsans/2587aa2d2d194ff2b966 to your computer and use it in GitHub Desktop.
app.factory("Movies", function($http, $q) {
return {
get: function() {
var deferred = $q.defer();
$http.get('movies.json')
.then(function(response){
deferred.resolve(response.data);
})
.catch(function(error){
deferred.reject(error);
});
return deferred.promise;
}
}
})
...
app.controller("MoviesCtrl", function($scope, Movies) {
Movies.get().then(function(data){
$scope.movies = data;
})
.catch(function(error){
console.log(error);
});
})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment