Keep checkbox checked after navigating away from page

≡放荡痞女 提交于 2019-12-25 00:36:24

问题


I have a check box that I need to keep checked after navigating away from the page. I am using AngularJS and bootstrap. Right now I am resetting the bound variable to false every time I reload the page (when the controller runs): how can I store my most up to date variable ($scope.disableCheck)?

In my controller....

$scope.disableCheck = false;
$scope.removeCheck = function () {
   $scope.disableCheck = !$scope.disableCheck;
}

And in my HTML...

<input class="notification-checkbox" type="checkbox" value="{{disableCheck}}" ng-click="removeCheck()" ng-clicked="{{disableCheck}}">

回答1:


Try using $rootScope instead. It is global to all controllers

Something like this

.controller('someCtrl', function($scope, $rootScope) {
  $rootScope.disableCheck = true;//set root scope here and refer to it as needed from other controlers
})


来源:https://stackoverflow.com/questions/24638375/keep-checkbox-checked-after-navigating-away-from-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!