AHméd Net AHméd Net - 1 month ago 9
AngularJS Question

How to detect the completion of HTTP request in angular1

is there any possibility to detect the completion of HTTP request in angular1 ?

product factory :

app
.factory('productFactory', ['$http','config',
function($http,config) {
var url = config.domainBase +':'+config.domainPort +config.additionalPath+'/Product/All'
return {
getAll: function() {
return $http.get(url);
}
};
}
]);


Product Controller :

var req = productFactory.getAllServers();
req.success(function(response) {
//....
}).
error(function(error){
//error
});

Answer

Take a look at $q injector

var deferred = $q.defer();
var params = {
  ...
};
$http.post('http://www.example.com', JSON.stringify(params))
  .success(function(object) {
    // On success
  })
  .error(function(object, status) {
    // On error
  });
return deferred.promise;

Comments