Skip to content

Instantly share code, notes, and snippets.

@tastycode
Created May 1, 2014 18:08
Show Gist options
  • Save tastycode/90a8b38e11be463669ba to your computer and use it in GitHub Desktop.
Save tastycode/90a8b38e11be463669ba to your computer and use it in GitHub Desktop.
Convert $http promise to regular promise
Article.prototype.comments = function() {
var url = RouteIndex.comments($scope.article.id).relative();
var deferred = $q.defer();
$http.get(url).success(function(comments) {
deferred.resolve(comments);
});
return deferred.promise;
};
//usage
$scope.article.comments().then(function(comments) {
$scope.comments = comments;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment