I am new in angular js and implementing single page application. I have implemented one checkbox and when I checked checkbox then I want to persist status of the checkbox after reloading. So When I click on the checkbox then storing the status(checked or unchecked) in session through $on($destroy) in Angular js.
I have seen one link Keep checkbox checked after page refresh AngularJS, But this is not working in my case.
I am sharing my sample code.
HTML
<input type="checkbox" id="mycheckbox" class="checkbox style-0" name="mycheckbox" ng-model="mycheckbox" data-ng-change="confirm()" autocomplete="off"/>
CONTROLLER:
$scope.confirm = function(){
if($scope.mycheckbox== false)
{
sessionStorage.setItem("confirmCheck", $scope.mycheckbox);
}
if($scope.mycheckbox== true){
sessionStorage.setItem("confirmCheck", $scope.mycheckbox);
}
}
if(sessionStorage.confirmCheck == "true"){
$('#mycheckbox').prop('checked',true);
}else {
$('#mycheckbox').prop('checked',false);
}
$scope.$on('$destroy',function(){
sessionStorage.confirmCheck=sessionStorage.getItem('confirmCheck');
})
I am able to storing the status of checkbox in session, But I can't able to change status in HTML page.When I navigate to another page and return back to previous page then value is persist in angular controller but not updated in HTML page. Please share your idea. thanks in Advance.
