I have a list object in the parent state of this controller. Every time I load the state that uses this controller, $scope.items is emptied and the controller must load the data from the parent scope again.
ListCtrl corresponds to the list state. The parent state contains many lists.
.controller('ListCtrl', ['$scope','$state','$timeout',
function($scope, $state, $timeout) {
console.log($scope.items); // undefined
if(!$scope.items) { // always evaluates to true
$timeout(function() {
$scope.items = $scope.$parent.list.items;
}, 500);
} else {
console.log($scope.items); // never executes here
}
}])
It was my understanding that AngularJS by default caches some views. Does this mean the caching does not apply to the scope variables in the cached views? And most importantly, is there a way to cache this $scope.items so that every time I return to this state, there isn't this timeout delay?
Aucun commentaire:
Enregistrer un commentaire