Alert() doesn't work when return to the previous tab page


#1

hello,

there are two tab page, we say tab-A and tab-B
tab-A controller has alert notice. when load tab-A the first time. alert can work
when $state.go(‘tab-B’) and then $stae.go(‘tab-A’) again. alert doesn’t work

$scope.variable has the same. can’t be changed when return to the previous page.

Could anyone explain the reason?


#2

This is because Ionic caches views and its associated controller. This is how view transitions look super fast.
If you want to run some code in your controller each time the view comes into focus do:

.controller('YourCtrl', function($ionicView) {
     $ionicView('enter', function() { 
       //your alert code here
      })
  })