I have a factory which stores and periodically updates some data using a service($http call). I want the busy indicator in the view every time the data is being updated. The factory exposes the data object and the promise.
angular.module('myUI')
.factory('statusFactory', function ($timeout, statusService) {
var promise = {};
var data = {};
function update(){
angular.extend(promise, statusService.status().$promise).then(function(response){
angular.extend(data, response);
});
$timeout(update, 10000);
}
update();
return{
data: data,
promise: promise
}
});
In the controller, I bind these variables to scope:
$scope.statusPromise = statusFactory.promise;
$scope.data = statusFactory.data;
And finally in the view I present the data
<div cg-busy="statusPromise">
{{data.var1}}
{{data.var2}}
...
</div>
Now the data is being updated flawlessly, but cg-busy does nothing. I would expect the busy icon every time the $http call is being resolved. It works when I use the statusService directly in the controller.
Is there some better way to do it? How can I expose some persistent promise from the factory so that it updates view on every new call?