I have a view that uses a LocalStorage variable called Entity .
/* Entity Service */
.factory('EntityService', function (){
return {
getEntity : function(){
return JSON.parse(window.localStorage['entity'] || false);
}
};
})
/* Route definition */
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl',
resolve : {
Entity : function(EntityService){
return EntityService.getEntity();
}
}
})
/* AppCtrl*/
.controller('AppCtrl', function($scope,Entity) {
$scope.model = {
entity : Entity
};
})
/* AppCtrl (view) */
<ion-view view-title="{{ model.entity.name }}">
<ion-content>
<div class="padding">Home</div>
</ion-content>
</ion-view>
/* EntitiesCtrl */
$scope.setEntity = function(entity){
window.localStorage['entity'] = JSON.stringify(entity);
$state.go('app.home');
}
/* EntitiesCtrl (view)*/
<div class="list">
<a class="item item-thumbnail-left" ng-click="setEntity(entity)" ng-repeat="entity in model.entities">
<img src="img/entities/{{ entity.logo }}">
<h2>{{ entity.name }} - {{ entity.acronym }}</h2>
<p>{{ entity.city.name }} - {{ entity.city.state.acronym }}</p>
</a>
</div>
The entity variable value changes within the Controller Entities, but when the $state.go('app.home')
is called, the value of the variable is changed but the view continues with the old value of the variable. p>
{{ model.entity.name }}
When $state.go('app.home')
is executed, the controller does not run again (checked with console.log();
).
What do I need to do to get the controller to look for the new variable value every time that $state.go('app.home')
is called?