Controller is not aware of changed $stateParams


#1

Hello,
I use $stateParams as a paramter to load data from an json object ; as you can see below. You can click in list from several items - this changes the $stateParam - and then get to a new state with some detail information.But now $stateParams is not changing in my controller or loading the data as expected. It will load the data with the index of first item I clicked, but not refresh when I chose another item with another indexnumber from the list. However when I refresh the page, the url contains proper $stateParams, evrything works as expected. And it was working in the past-
Is there any possibilty to force the controller to update its $stateParams value? Or do you have experience why is this so?

     controllers.controller('DetailController', ['$scope', '$http', '$state', '$stateParams','$ionicHistory',
          function($scope, $http, $state, $stateParams, $ionicHistory){

       
   
  
  $http.get('res/data_beispiel.json').success(function(data) {
           
        
        $scope.bars=data;

  $scope.bar = $scope.bars[$stateParams.Id];
  $scope.show = false;
    })
    .error(function(data) {
    alert("$http get method failed!");
        
        
    });
        
          
$scope.goback = function() {
    $state.go('list.bars');
  };
        
        }]);


app.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('login', {
      url: "/login",
      templateUrl: "templates/login.html",
      controller: 'LoginController'
      
    })
    .state('list', {
        url: "/list",
         abstract: true,
        templateUrl: "templates/logged_in.html"
    })
    .state('list.bars', {
        url: "/bars",
        views:{
            'list-view': {
        templateUrl: "templates/list.html",
        controller: "ListController"
        
            }}
    })
    .state('list.bars.bar', {url: '^/bars/:Id', views: {'@': { templateUrl: 'templates/detail.html', controller: 'DetailController'}},})
    .state('list.settings', {
        url: "/settings",
        views:{
            'list-view': {
        templateUrl: "templates/settings.html",
        controller: "ListController"
            }}
    })
    
    
$urlRouterProvider.otherwise("login");

})    ;

#2

Search the official docs or this forum for $ionicView caching, there are several ways to do what you want.


#3

Yes, works perfect, thanks.

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