我有一个使用 LocalStorage 对象变量(称为实体)的视图。
/* 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>
LocalStorage 变量entity的值在 EntitiesCtrl 中改变了,但是当 $state.go('app.home') 显示 Home 视图时,值在 EntitiesCtrl 中没有改变
{{ model.entity.name }}
每次$state.go('app.home');时,我能做些什么来获取window.localStorage['entity'] 的新值;叫做?
谢谢!