In my app I have a service that asynchronously returns cached value:
.service('StateService', [
'$q',
function ($q) {
var value;
// ...
// ...
function getValue() {
return $q.when(value);
}
// ...
// ...
return {
getValue: getValue
// ...
// ...
};
}
]);
Static variable "value" is updated via setter in the same service.
It is a requirement to have getter getValue()
that works asynchronously - the idea is to implement an id cache in the future.
In the main controller I need to $watch
changes to StateService.getValue()
and update scope with new value
if it was changed.
Is there a possibility to $watch
promises (that are not actually a resource calls, but just a static value wrapped in a promise) with $scope.$watch
?
Maybe by unwrapping them in every digest and comparing old a new value?