ionic controller not called after $state.go

2019-05-02 09:58发布

i have a controller the get data from my back-end application, when opening the state for the first time from the first controller it loads the data, but when it try to open it again it does not load the new data

here is how

if (selectedServiceID == "000")
{
  $state.go('balanceInquery'); 
};

here is the called balanceInquery state controller

.controller('BalanceInqueryController', function($scope, getAccountBalanceService, $state, $ionicLoading, $ionicPopup) {
  getAccountBalanceService.get(username, pass, customerID, serviceAccID, langID)
    .success(function(data) {
      $scope.custBalance = data;
    })
    .error(function(data) {
      var alertPopup = $ionicPopup.alert({
        title: 'Error!',
        template: 'Sorry something went wrong'
      });
    });
})

2条回答
放我归山
2楼-- · 2019-05-02 10:39

I had a similar problem. The first time was shown only after reload. The reason is view caching. Disable it with cache: false, like in my specific case:

$stateProvider
  .state('login', {
    url: '/login',
    controller: 'LoginCtrl as vm',
    templateUrl: 'app/login/login.html'
  })
  .state('tab', {
    url: '/tab',
    abstract: true,
    templateUrl: 'templates/tabs.html',
    cache: false
  })
查看更多
乱世女痞
3楼-- · 2019-05-02 10:42

This is due to view caching, which can be disabled in a variety of ways. See http://ionicframework.com/docs/nightly/api/directive/ionNavView/ for more details.

查看更多
登录 后发表回答