reload: true works only once

2019-09-04 12:31发布

问题:

I am trying to pass parameters from one view to another in my anulgar/ionic app.

in the volCompute view ($stateParams is declared):

if ($stateParams.modelLine){
    console.log('receiving', $stateParams.modelLine.id, $stateParams.modelLine.modelStrict)
    $scope.data.chosenModel = $stateParams.modelLine.modelStrict;
}

in the compareview:

$state.go('app.volCompute', { modelLine: test[0] }, {reload: true});

but it works only one time, if I go back and forth between the two views the code in volCompute is not run. It seems like the reload: true is only executed once.

Can you help please ?

回答1:

There are few more details how to understand ionic caches

  • What is the difference between $ionicView.enter and cache:false
  • ui.router not reloading controller

And I would suggest to use the event hook here $ionicView.enter or $ionicView.afterEnter

$scope.$on('$ionicView.enter', function(){
  // Coding
});

there is the link to doc



回答2:

In your routes file:

$stateProvider.state('myState', {
   cache: false,
   url : '/myUrl',
   templateUrl : 'my-template.html'
})

Or inidividually in an <ion-view> tag:

<ion-view cache-view="false">
    ...
</ion-view>