导航离开页面后,请保留复选框 [英] Keep checkbox checked after navigating away from page

查看:99
本文介绍了导航离开页面后,请保留复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框,我需要在导航离开页面后继续检查。我使用AngularJS和bootstrap。现在我每次重新加载页面(当控制器运行时)将绑定变量重置为false:如何存储我最新的变量( $ scope.disableCheck )?

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)?

在我的控制器中。

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

在我的HTML ...

And in my HTML...

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


推荐答案

请尝试使用$ rootScope。这是所有控制器的全局

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

像这样

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

这篇关于导航离开页面后,请保留复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆