Created
May 1, 2014 18:08
-
-
Save tastycode/90a8b38e11be463669ba to your computer and use it in GitHub Desktop.
Convert $http promise to regular promise
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
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