I have an Angular JS application and I want to do a global action every second when the route changes successfully. So I created a .run() block in which I DI $interval and use the $interval on $routeChangeSuccess. The strange thing is that after each route change, the interval starts fireing faster and faster. This is my code:
app.run(["$interval", "$rootScope", function($interval, $rootScope){
$rootScope.$on("$routeChangeSuccess", function(event, current){
if(current.$$route.authenticate){
$interval(function(){
console.log("whatever");
}, 1000);
}
});
}]);
To conclude, the "whatever" console log starts firing faster and faster. Is it because the $interval is a Singleton so it gets recreated each time? But why isn't the old $interval deleted?