我正在尝试在localStorage中设置值。函数调用后,我试图更改该值。请检查我的代码
这是我的js角函数
localStorage.setItem("popupstatus", true);
$scope.loadInitialPopUp = function (){
if ( localStorage.getItem("popupstatus") === true){ //only show if they haven't seen it.
$scope.openPopup();
}
}
$scope.openPopup = function () {
var modalInstance = $uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
controller: 'popupPeriodCtrl',
scope: $scope,
resolve: {
},
templateUrl: 'modules/popup-period/popup-period.html'
});
localStorage.setItem("popupstatus", false);
};
我正在HTML页面中调用上述功能
<div ng-init="loadInitialPopUp()"> </div>
我需要从localStorage中设置的值加载此弹出窗口。我该怎么办?
答案 0 :(得分:1)
getItem方法将返回一个String而不是一个布尔值。尝试做
if (Boolean(localStorage.getItem("popupstatus"))){
$scope.openPopup();
}