我只想将我的范围值存储在android内存中。因为我在重新启动应用程序时松开了所有ListItem。有没有办法保留所有控制器的范围值?
我的控制器:
App.controller('MessageCtrl', ['$scope', function($scope){
$scope.title = "My Title";
$scope.items;
if($scope.items == undefined || $scope.items == []){
console.log("Empty items found");
$scope.items = [];
}
$scope.number = '';
$scope.message = '';
$scope.addItem = function () {
console.log('Adding Item..');
$scope.items.push({
number: $scope.number,
message: $scope.message
});
};
$scope.deleteItem = function(index){
console.log("Deleting item - "+index);
$scope.items.splice(index, 1);
};
}]);
列表视图:
<ion-list class="list" show-delete="shouldShowDelete">
<ion-item class="item item-avatar" ng-repeat="item in items">
<ion-delete-button class="ion-minus-circled" ng-click="deleteItem($index)"></ion-delete-button>
<img src="img/default_avatar.png">
<h2>{{item.number}}</h2>
<p>{{item.message}}</p>
</ion-item>
<ion-toggle ng-model="shouldShowDelete">
Show Delete?
</ion-toggle>
</ion-list>
我想保留$ scope.items数组。这样我就可以在用户重启应用程序时呈现List。
任何建议都会对我有所帮助。