If checkbox is checked then after reloading checkbox should be checked , If unchecked then should be unchecked.
Using in directive controller.
var checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {},
$checkboxes = $("#checkbox-container :checkbox");
$checkboxes.on("change", function(){
$checkboxes.each(function(){
checkboxValues[this.id] = this.checked;
});
localStorage.setItem("checkboxValues", JSON.stringify(checkboxValues));
});
// On page load
$.each(checkboxValues, function(key, value) {
$("#" + key).prop('checked', value);
});
<script src="http://ift.tt/1cljup6"></script>
<div id="checkbox-container">
<div>
<label for="option1">Option 1</label>
<input type="checkbox" id="option1">
</div>
</div>
Above code I took from this http://ift.tt/25ms3xQ
Above code is working fine. I am also using the Anguglar js. When I using in ng-model then value $("#" + key).prop('checked', value);
is not make checked checkbox in html page.
<input type="checkbox" id="option1" ng-model="mycheckbox" data-ng-change="call()" />
Javascript controller:
$scope.call=function(){
console.log("inside controller");
}
So in this case JQuery is not able to make true(checked) and false(unchecked) in html page. But if I don't use ng-model then It will works.
Aucun commentaire:
Enregistrer un commentaire