Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$q example
.factory('ourFactory', function($http, $q){
return {
update: function(){
var defer = $q.defer(); // we're gonna create a new promise to return
$http.get('http://google.com').success(function(data){
d.resolve(data); // This is what we can access from our promise later
});
return d.promise; // return the promise
}
};
});
.controller('name', function(ourFactory){
ourFactory.update().then(function(data){ // that data we resolved into our promise in the factory is accessible now
$scope.something = data; //now you can bind that data to your scope
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment