gpt4 book ai didi

javascript - 保存到本地存储已打开,如果为 false,则删除本地存储

转载 作者:行者123 更新时间:2023-12-03 06:26:16 26 4
gpt4 key购买 nike

我正在开发一个使用 ionic 和 angularjs 的应用程序,这就是我想要实现的目标,当切换开关打开时,它应该将本地存储设置为 true,当它关闭时,它应该删除本地存储。

.controller('shops',['$scope','$http','$timeout',function($scope,$http,$timeout) {
$http.get('http://localhost/work/templates/source.php').success(function(data){
$scope.shops=data;
});

$scope.pushNotificationChange = function(item) {
$timeout(function() {
if ($scope.pushNotification = { checked: true }) {
alert("false");
}
//alert('Push Notification Change: '+ $scope.pushNotification.checked);

localStorage.setItem("shop_id",($scope.item.shop_id));
}, 0);
};
}]);

HTML

<div align="right">
<label class="toggle toggle-balanced">
<input type="checkbox"
ng-model="pushNotification.checked"
ng-change="pushNotificationChange()">
<div class="track">
<div class="handle"></div>
</div>
</label>
</div>

最佳答案

编辑:有更明确的答案

<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

<title>Toggles</title>

<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>

<body ng-controller="MainCtrl">

<ion-header-bar class="bar-positive">
<h1 class="title">Toggles</h1>
</ion-header-bar>
<ion-content>
<ion-toggle ng-model="pushNotification.checked"
ng-checked="pushNotification.checked">
{{ pushNotification.text }}
</ion-toggle>
<div class="">
{{pushNotification.checked}}
</div>
</ion-content>
</body>
</html>

你的js代码将是

angular.module('ionicApp', ['ionic'])

.controller('MainCtrl', function($scope) {

$scope.pushNotification = {};
$scope.pushNotification.text = "Sample"
$scope.pushNotification.checked = false;

$scope.pushNotificationChange = function() {
console.log('Push Notification Change', $scope.pushNotification.checked);
if($scope.pushNotification.checked){
//set your local storage
}else{
//remove from local storage.
}
};

});

关于javascript - 保存到本地存储已打开,如果为 false,则删除本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38640375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com