Hi Martin,
Ah, well, that’s indeed a good reason to want this. I don’t have a
waterproof solution for this, but the wrote the following for you. It will
trigger when no digest has occurred for 500ms
app.run(['seDigestwatcher', '$rootScope', function (seDigestwatcher, rS) {
// Set up the digestwatcher in the run, so it's available during
// the whole lifetime of the app.
seDigestwatcher.setScope(rS); //Make it watch the rootscope.
seDigestwatcher.registerDigests(); //start watching.
}]);
app.factory('seDigestwatcher', [
function() {
var timeOutId,
rs = null;
me = this,
digestCounter = 0;
unWatch = null;
this.registerDigests = function() {
console.log('start watching');
unWatch = rs.$watch(function() {
digestCounter += 1;
me.cancel(); //cancel pening timeout
// set up a timeout to signal after no new digest
// is starterd within 500Ms. If you have really
// long running functions, or ajax stuff
// you might need to set a bigger timeout
timeOutId = setTimeout(me.signal,500) ;
});
};
this.deRegisterDigests= function () {
if (unWatch) {
me.cancel();
unWatch();
}
};
this.cancel = function () {
if (timeOutId) {
clearTimeout(timeOutId);
timeOutId = null;
}
};
this.setScope = function (scope) {
rs=scope;
};
this.signal = function () {
me.cancel();
console.log(digestCounter);
};
return {
registerDigests: me.registerDigests,
deRegisterDigests: me.deRegisterDigests,
setScope : me.setScope
};
}
]);
you can see it in action in this plunker:
http://plnkr.co/edit/Sud2Y0VFy3SH3QtZojg7?p=preview
Just adapt the signal function to what you need it to do.
Regards
Sander
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.