Created
July 11, 2014 09:26
-
-
Save steve228uk/5a8401f766f2673f9bff to your computer and use it in GitHub Desktop.
$q example
This file contains hidden or 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
.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