0

I am trying to set values in localStorage. After the function call I am trying to change that value. please check my code

this is my angular js function

 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);
    };

I am calling above function in my Html page

<div ng-init="loadInitialPopUp()"> </div>

I need to load this pop up, from the values set in localStorage. How do I do it?

2
  • when popup load first time, i try to save value in the local storage. after the loading popup that value i change. thats my requirement Commented May 18, 2020 at 10:53
  • i am trying to load popup only one time. unless when page reload, this popup function calling. i need to stop it Commented May 18, 2020 at 10:54

1 Answer 1

1

The getItem method would return a String and not a boolean value. Try doing

if (Boolean(localStorage.getItem("popupstatus"))){
    $scope.openPopup();
}
Sign up to request clarification or add additional context in comments.

3 Comments

how i check true or false ?? can u help me
@gihankumara can you rephrase your question ? what exactly do you want to check ?
If you know that the value in a certain localStorage is Boolean. Then you need to convert it into a Boolean on the js side by Sending the value from the getItem method to the Boolean contruction (Boolean(value)). The localStorage only returns string values, so if you compare with a string Boolean it is not a good coding practice to do so. Hope you get what I'm trying to say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.