NgStorage - Reset to default

I am using ngStorage for web storage.

And this is the code I am currently using to check if a parameter is defined $localStorage

.

if ( angular.isDefined($localStorage.settings) ) {
    $scope.app.settings = $localStorage.settings;
} else {
    $localStorage.settings = $scope.app.settings;
}

      

And this is my controller script.

.controller('MainCtrl', function($scope, $localStorage) {

    $scope.app = {
        settings: {
            name: 'AppName',
            headerFixed: true,
            version: 'Initial Release'
        }
    }

    if ( angular.isDefined($localStorage.settings) ) {
        $scope.app.settings = $localStorage.settings;
    } else {
        $localStorage.settings = $scope.app.settings;
    }

    $scope.resetStorage = function() {
        $localStorage.$reset();
    }

})

      

HTML:

<div class="main-content" ng-controller="MainCtrl" ng-class="{'header-fixed': app.settings.headerFixed}">

        <input type="checkbox" name="name" ng-model="app.settings.headerFixed"> Header Fixed

        {{ app.settings.headerFixed }}

        <button type="button" name="button" ng-click="resetStorage()">Reset</button>

</div>

      

I am using the rest method provided in this link but it doesn't work.

Someone help me to reset my values ​​to their defaults when I press the reset button where I call the function resetStorage()

.

Thanks in advance.

+3


source to share


1 answer


You must store two variables to use a different restore target. because I think there is no such method that can go back to previous data.



0


source







All Articles