I have a problem accessing the functions properties from nested functions. I'm sure I've missed something, but after 3 hours of Google I just don't know what to look for. The background: I want to add a controller to angularjs, that reload the page after a certain time. My problem is the access from "this.reloadTicker()" to "this.enabled". The idea to rename the controller function and then access them doesn't work. One solution would be to store everything in "$scope", but is there a better solution?
My code:
ctrls.controller("reloaderCtrl", function reloader($scope) {
this.enabled = true;
this.paused = false;
this.maxSecs = 30;
this.secs = 30;
this.reloadTicker = function() {
if (reloader.enabled && !reloader.paused) {
if (reloader.secs > 0) {
reloader.secs--;
} else {
reloader.reload();
reloader.secs = reloader.maxSecs;
}
$scope.$apply();
}
setTimeout(this, 1000);
}
this.reload = function() {
$scope.$emit('doReload');
}
setTimeout(this.reloadTicker, 1000);
});