我只想将我的范围值存储在 android 内部存储器中。因为我在重新启动应用程序时丢失了所有 ListItems。有没有办法保留所有控制器的范围值?
我的控制器:
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 数组。这样我就可以在用户重新启动应用程序时呈现列表。
任何建议都会对我有很大帮助。