Wondering if this is expected behavior, I have a parent state (location) with a couple child states (details, history etc) where the parent has an ID parameter deciding which location to load. I tried using the various $ionicView events to call my load data function, but the $stateParams service is still cached I believe and always returns the value of the first location that got loaded. Has anyone else seen this or can confirm that this is expected behavior? If it is, seems like a bug in the caching to not be able to reuse a generic page that load different data depending on a parameter.
Same here, stateParams still have the first time data, even if i have register to $ionicView.enter event !! Please how can i empty the $stateParams cache ??? or any workaround ?
Hey, I had the same problem. This is the workaround I’ve used: in your main controller (of the parent state) cache the id that arrives and use it when navigating to your child states:
(function(){
'use strict';
angular
.module('app.debtor')
.controller('Debtor', Debtor);
Debtor.$inject = ['$scope', '$stateParams', '$state'];
function Debtor($scope, $stateParams, $state) {
$scope.data = {};
$scope.navigate = function(ref) {
$state.go(ref, {uuid: $scope.data.uuid});
};
$scope.$on('$ionicView.beforeEnter', function() {
$scope.data.uuid = $state.current.data.params ? $state.current.data.params.uuid : $stateParams.uuid;
});
}
}());
the navigate function I use is called from tabs ng-click with following params:
ng-click="navigate('^.childstate');"
2 Likes