解决办法
$scope.$on('$ionicView.enter', function(e) {
//你要执行的代码放里面,这样保证每次都会执行
});
或者,
在ui-router里面禁止cache,加上cache:false
...
.state('tab.somepage', {
url: '/somepage',
cache:false, //加一句
templateUrl: 'somepage.html'
})
...
原因,引用Ionic官方文档:
因为Ionic的新的视图缓存,controller只会在创建的时候调用一次,而不是每次页面变化时
With the new view caching in Ionic, Controllers are only called when they are recreated or on app start, instead of every page change.