The issue you're having is due to the fact the timeout is not cleared when the $scope is destroyed.
You need to manually clear the timeout by listening to the $destroy
event. This event originates from Angular and is thrown whenever a $scope is destroyed. Try adding the following to your controller (I did not test this, so consider this pseudo code)
$scope.$watch('$destroy', function(){
$timeout.cancel($scope.timeoutCountdown);
});
Edit:
You could also do this right before changing the route:
$scope.redirectToHome = function() {
$timeout.cancel($scope.timeoutCountdown);
$scope.safeApply(function() { $location.path("/portale"); });
};
Just keep in mind that if you have other redirect possibilities (i.e. other buttons the user could use to navigate from the login/-out page), you'd need to do this for each of those (or preferably wrap it in a method).