In my ionic application, I have several views. When I launch the app, it takes me to the main view where data is loaded upon initialization of the controller.
The issue arises when I navigate away from this view using tabs; sometimes the controller gets destroyed. As a result, when I return to the view, the data has to be reloaded.
I've experimented with '$ionicView.loaded' and '$ionicView.unloaded', but it seems that the unloading of the view is somewhat random.
This is how my state configuration looks:
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('login', {
name: "login",
url: "/login",
templateUrl: "templates/login.html",
controller: 'loginCtrl'
})
// Sidemenu here
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html'
})
.state('app.hms', {
url: '/hms',
views: {
'menuContent': {
templateUrl: 'templates/hms-app.html',
controller: 'HmsCtrl'
}
}
})
... // Other states defined similarly
// Fallback route
$urlRouterProvider.otherwise('login');
});
My tabs are specified in each respective HTML template after closing ion-content:
<div class="tabs tabs-icon-top">
<a class="tab-item" href="#/app/hms">
<i class="icon ion-home"></i>
Home
</a>
... // Additional tab definitions
</div>
Any insights on what could potentially lead to the destruction of the view's controller during navigation?