问题
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