I'm using ngStorage for web storage.
And this is the code I'm currently using to check whether the $localStorage
is defined or not.
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'm using the rest method as given in the this link, but it doesn't work.
Someone help me out to reset my values to the default values when I click a reset button where I'm calling the function resetStorage()
.
Thanks in advance.
You should keep two variables one for use another for restore purpose . because i think no such method available that can restore back to the previous data.