Ionic caches views for faster performance. It uses feature of ng-router
.
Ionic will cache a maximum of 10 views, and not only can this be configured, but apps can also explicitly state which views should and should not be cached.
http://ionicframework.com/docs/api/directive/ionNavView/
There are multiple ways to address this issue.
Option 1
If you want controller to execute everytime the view is shown, you can disable cache for that particular route.
$stateProvider.state('myState', {
cache: false,
url : '/myUrl',
templateUrl : 'my-template.html'
})
or
<ion-view cache-view="false" view-title="My Title!">
...
</ion-view>
Option 2
You can disable cache for all views. And even control the number of views. I don't know if this could be useful to you or not.
$ionicConfigProvider.views.maxCache(0);
Option 3
My favourite. You can use $ionicView.enter
event. This guarantees that the code that needs to be executed when the view is should would be executed. So you can differentiate code should be executed one time and every time. I guess this would have positive impact on performance.
Usage
$scope.$on('$ionicView.enter', function(){
// Coding
});
Good luck and happy coding!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…