Solution here is: DO clean after ourselves.
...
Add teardown code to controllers and directives
Controller and directives emit an event right before they are destroyed. This is where you are given the opportunity to tear down your plugins and listeners and pretty much perform garbage collection.
Subscribe to the $scope.$on('$destroy', ...) event
So, instead of this (there is a updated plunker)
controller: function($timeout) {
$timeout(function() {
alert("Hey I'm message from route 1!");
}, 5000)
}
we should do this:
controller: function($scope, $timeout) {
var removeTimer = $timeout(function() {
alert("Hey I'm message from route 1!");
}, 5000)
$scope.$on('$destroy', function(){
$timeout.cancel(removeTimer);
console.log('all cleared')
});
}
Not saying - that $http has cancel... it will simply later or sooner come from server...
The point is, if there are any ghost actions which could be triggered when repsonse comes (inside of .then()
) we should either clear them or check if the state has not gone...
Check it here