Is there a way to display a message on the scope indicating that a function in a service is currently being calculated and taking a long time? I have set up a simplified example in this jsfiddle: http://jsfiddle.net/rikboeykens/brwfw3g9/
var app = angular.module('myApp', []);
app.service('testService', function(){
this.longFunction=function(){
for (var i=0; i<1000000000;i++){
}
}
});
function TestCtrl($scope, testService)
{
$scope.$apply(function(){$scope.waiting="not waiting";});
$scope.longFunction = function(){
$scope.waiting="waiting";
testService.longFunction();
$scope.waiting="not waiting";
}
}
The longFunction on the testService takes about two seconds to complete, but $scope.waiting is not updated to "waiting" while this is taking place.
I tried using $scope.$apply but then I just get an error saying $apply is already in progress.
Would it work if I perform the longFunction on the testService asynchronously? I have been looking into using promises but I'm not sure how I would go about implementing them.