我想从本地存储中检索上次更新的值。 我的代码是:
$scope.saved = localStorage.getItem('ids');
$scope.ids = JSON.parse($scope.saved);
localStorage.setItem('ids', JSON.stringify($scope.ids));
console.log($scope.ids)
$scope.LogIn = function() {
if($scope.id=='1'){
$state.go('app.playlists');
}
$scope.ids = [];
$scope.ids.push({text:$scope.id});
localStorage.setItem('ids', JSON.stringify($scope.ids));
};
答案 0 :(得分:0)
您可以使用$scope.ids.length-1
获取数组的最后一个索引
$scope.saved = localStorage.getItem('ids');
$scope.ids = JSON.parse($scope.saved);
console.log($scope.ids[$scope.ids.length-1])