我正在使用離子和angularjs的應用程序,這是我想實現的,當切換開關是它應該設置localstorage爲true,當它已關閉,應刪除本地存儲。保存到localstorage切換和刪除localstorage如果它的假
.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>
,什麼是錯誤?你期望的行爲是什麼? – CozyAzure
爲什麼使用'if($ scope.pushNotification = {checked:true})'而不是'if($ scope.pushNotification.checked)'? – Lex