I\'m building an app with angular+ionic that uses a classic three-button menu at the bottom with three ion-tabs in it. When a user clicks a tab, that template opens through
For example to @Michael Trouw,
inside your controller put this code. this will run everytime when this state is entered or active, you do not need to worry about disabling cache and it's a better approach.
.controller('exampleCtrl',function($scope){
$scope.$on('$ionicView.enter', function(){
// Any thing you can think of
alert("This function just ran away");
});
})
You can have more examples of flexibility like $ionicView.beforeEnter -> which runs before a view is shown. And there are some more to it.
I had a similar problem with ionic where I was trying to load the native camera as soon as I select the camera tab. I resolved the issue by setting the controller to the ion-view component for the camera tab (in tabs.html) and then calling the $scope method that loads my camera (addImage).
In www/templates/tabs.html
<ion-tab title="Camera" icon-off="ion-camera" icon-on="ion-camera" href="#/tab/chats" ng-controller="AddMediaCtrl" ng-click="addImage()">
<ion-nav-view name="tab-chats"></ion-nav-view>
</ion-tab>
The addImage method, defined in AddMediaCtrl loads the native camera every time the user clicks the "Camera" tab. I did not have to change anything in the angular cache for this to work. I hope this helps.
Considering Ionic's ability to cache view elements and scope data mentioned above, this might be another way of doing, if you want to run the controller every time the view gets loaded. You can globally disable the caching mechanism used by ionic by doing:
$ionicConfigProvider.views.maxCache(0);
Else, the way I had it working for me was doing
$scope.$on("$ionicView.afterLeave", function () {
$ionicHistory.clearCache();
});
This is to clear the cache before leaving the view to re-run controller every time you enter back again.