Skip to content

Instantly share code, notes, and snippets.

@anton000
Last active August 29, 2015 13:56
Show Gist options
  • Save anton000/9094022 to your computer and use it in GitHub Desktop.
Save anton000/9094022 to your computer and use it in GitHub Desktop.
$http $q wrap
$scope.fetchData = function() {
if ($scope.async) {
$scope.async.reject();
}
$scope.async = testAsync();
$scope.async.promise.then(
function(data){
console.log('success' + data);
},
function(data) {
console.log('reject' + data);
}
);
}
testAsync = function() {
var deferred = $q.defer();
$http.get('/api/')
.success(function(data) {
deferred.resolve(data);
})
.error(function(data) {
deferred.reject(data);
});
return deferred;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment