$ state.go () does not load the controller in the ionic application

Using the following code, when the first page with id=0 loads the first time, there are no problems with the controller. But when again the same page loads with the same id=0 again, it does not load the controller.

 $state.go('tab.dash', { id: $rootScope.products[CONSTANTS.i].id }, { reload: true }); 

How does this happen? Please offer me a solution.

+5
source share
2 answers

I ran into a similar problem when I need statistics to recount every time I visit a tab.

You need to disable view caching. You can do this in the route setup. For instance:

 .state('tab.stats', { url: '/stats', views: { 'tab-stats': { templateUrl: 'templates/tab-stats.html', controller: 'StatsCtrl' } }, cache: false }) 
+3
source

Well, when you cache the view (by default, this is true), the controller loads only for the first time and during subsequent navigation it will attach and separate the area. Cacheing helps with single page applications. If you do not want to disable caching, you use events with an ionic representation, for example (enter, leave, load, etc.).

  $scope.$on('$ionicView.enter', function () { // ur stuff in here.... }); 
0
source

All Articles