I would agree with Dylan Watt, though I think I would want to use $http's built promise, with success and error for a little cleaner handling if there is a problem.
Set a var that enabled the loading state, make your ajax call, change the loading state back on success of that ajax call (or do something else in case of an error).
$scope.getFunction = function () {
$scope.loading = true;
$http.get('/someUrl').
success(function(data, status, headers, config) {
$scope.names = data;
$scope.loading = false;
}).
error(function(data, status, headers, config) {
// gracefully handle the error here
});
}
If the above doesn't solve your issue, and the following is your concern:
no if you have lets say 1000s of rows in your response, then the time
when the $http finishes, and the time by when angular's digest cycles
get over.. there would be a significant lag... what the question ask
is - how to identify when the last digest cycle has finished – entre
One potential solution (though I am not convinced this is a great way) would be something along the lines of this post:
How to watch the DOM for changes AngularJS
and set a timeout to wait until no DOM changes occur for a set period of time. I have not seen anywhere that you can identify when the last $digest cycle occurs specifically. In the case of large amounts of data being blasted through ng-repeat, you should see a burst of DOM population, and then it should go quiet.
A better solution seems to be to use an 'element-ready' directive which triggers the $rootScope.loading = false
once it has loaded, as described in the following post:
Sending event when angular.js finished loading