在 angular js 中的“$on('$destroy')”中设置当前复选框值?
Set current checkbox value in "$on('$destroy')" in angular js?
我是 angular js 的新手。我正在实施复选框,我还想在重新加载和导航到另一个页面后防止重置复选框。现在,当我重新加载页面时,复选框将重置。所以我正在使用 $on("$destroy") 保存状态。但是我无法使用 $on("$destroy").
设置复选框当前值
HTML
<input type="checkbox" id="mycheckbox" class="checkbox style-0"
name="mycheckbox" ng-model="mycheckbox" data-ng-change="confirm()" />
ANGULAR 控制器:
$scope.confirm= function(){
if($scope.mycheckbox== false)
{
alert("inside unchecked");
}
else{
alert("inside checked");
}
}
$scope.$on('$destroy',function(){
sessionStorage.date=matchDate;
sessionStorage.maxValue=realValue;
sessionStorage.minValue=normalValue;
})
如何在 $on(destroy) 中设置选中或取消选中当前复选框值。我已经在 $on(destroy) 中设置了一些值,但是在复选框的情况下我很困惑。所以请分享你的想法。您的回答对提前 me.Thanks 有价值。
$on('$destroy')
表示控制器正在消失,因为页面已卸载。您必须像存储其他数据一样存储复选框的当前状态。然后在控制器初始化中,您可以检查复选框是否有存储值,以及是否使用它来初始化复选框而不是默认值。
var myApp = angular.module('myApp',[]);
myApp.controller('Controller', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
$scope.checkbox = (sessionStorage.hasOwnProperty('checkbox') ? sessionStorage.checkbox : false);
$scope.$on('$destroy',function(){
sessionStorage.date=matchDate;
sessionStorage.maxValue=realValue;
sessionStorage.minValue=normalValue;
sessionStorage.checkbox=$scope.checkbox;
})
}]);
我是 angular js 的新手。我正在实施复选框,我还想在重新加载和导航到另一个页面后防止重置复选框。现在,当我重新加载页面时,复选框将重置。所以我正在使用 $on("$destroy") 保存状态。但是我无法使用 $on("$destroy").
设置复选框当前值HTML
<input type="checkbox" id="mycheckbox" class="checkbox style-0"
name="mycheckbox" ng-model="mycheckbox" data-ng-change="confirm()" />
ANGULAR 控制器:
$scope.confirm= function(){
if($scope.mycheckbox== false)
{
alert("inside unchecked");
}
else{
alert("inside checked");
}
}
$scope.$on('$destroy',function(){
sessionStorage.date=matchDate;
sessionStorage.maxValue=realValue;
sessionStorage.minValue=normalValue;
})
如何在 $on(destroy) 中设置选中或取消选中当前复选框值。我已经在 $on(destroy) 中设置了一些值,但是在复选框的情况下我很困惑。所以请分享你的想法。您的回答对提前 me.Thanks 有价值。
$on('$destroy')
表示控制器正在消失,因为页面已卸载。您必须像存储其他数据一样存储复选框的当前状态。然后在控制器初始化中,您可以检查复选框是否有存储值,以及是否使用它来初始化复选框而不是默认值。
var myApp = angular.module('myApp',[]);
myApp.controller('Controller', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
$scope.checkbox = (sessionStorage.hasOwnProperty('checkbox') ? sessionStorage.checkbox : false);
$scope.$on('$destroy',function(){
sessionStorage.date=matchDate;
sessionStorage.maxValue=realValue;
sessionStorage.minValue=normalValue;
sessionStorage.checkbox=$scope.checkbox;
})
}]);