Is there a better way to get data from localStorage after storing the data without refreshing/reloading the page

I’m trying to make a button that could store the data to the localStorage. After storing the data, I want to get the data without refreshing/reloading the page

The way I use to fix this case is, I put 2 commands on a button. The first command is to store the data, and the second command is to get the data using $scope to make it easy to display it on the page

Here is my code

$scope.storeData = function(){
    if(localStorage.getItem('value') === null){
        $ = 'Selamat sore';
        localStorage.setItem('value', JSON.stringify($;
        $scope.getData = JSON.parse(localStorage.getItem('value'));
        $scope.getData = JSON.parse(localStorage.getItem('value'));

It’s actually working, but maybe there is a better way to do this


Source: AngularJS Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.