I have a weird issue with all of my controllers persisting across every state inside of an ion-tab.
My routes:
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html',
})
.state('tab.one', {
url: '/one',
views: {
'main-tab': {
templateUrl: 'templates/one.html',
controller: 'oneCtrl'
}
}
})
.state('tab.two', {
url: '/one/:id',
views: {
'main-tab': {
templateUrl: 'templates/two.html',
controller: 'twoCtrl'
}
}
})
.state('tab.three', {
url: '/one/:id/two/:twoId',
views: {
'main-tab': {
templateUrl: 'templates/three.html',
controller: 'threeCtrl'
}
}
});
The Main template holds a tab and all of the other view are shown inside of it:
<ion-tab title="tab" icon="icon ion-home" href="#/tab/patients">
<ion-nav-view name="main-tab"></ion-nav-view>
</ion-tab>
My problem is that when I change views a controller is created, but NEVER destroyed when I move to a new view. I can confirm this by adding a logger with timeout to each controller:
var onTimeout = function() {
$scope.value += 1;
console.log($scope.value);
$timeout(onTimeout, 1000);
};
$timeout(onTimeout, 1000);
$scope.value = 0;
This will continue logging from the previous view as a navigate to new views. WTH?
Am I using ion-tabs
incorrectly? I want to be able to refresh data on certain views, but since the controller is never destroyed, it cannot update its scopes.
ie: if I am in tab.three
and I call $state.go('tab.one', {}, {reload: true})
then my resolve
property in the controller will be triggered, but the new data will never be assigned in the controller as the controller is still running.