Search code examples
angularjsangularjs-service

AngularJS Execute function after a Service request ends


I am using AngularJS Services in my application to retrieve data from the backend, and I would like to make a loading mask, so the loading mask will start just before sending the request. but how can I know when the request ends?


For example I defined my servive as:

angular.module('myServices', ['ngResource'])
    .factory('Clients', function  ($resource) {
        return $resource('getclients');
    })
    .factory('ClientsDetails', function  ($resource) {
        return $resource('getclient/:cltId');
    })

So I use them in my controller as:

$scope.list = Clients.query();

and

$scope.datails = ClientsDetails.get({
    date:$scope.selectedId
});

So the question would be, how to know when the query and get requests ends?


Edit:

As a side note in this question I've been using using angularjs 1.0.7


Solution

  • As left in a comment by Pointy I solved my problem giving a second parameter to the get function as following:

    $scope.datails = ClientsDetails.get({
        date:$scope.selectedId
    }, function(){
        // do my stuff here
    });