Skip to content

Instantly share code, notes, and snippets.

@justinwinslow
Created December 13, 2014 07:01
Show Gist options
  • Save justinwinslow/9b9629ea7221ec08b177 to your computer and use it in GitHub Desktop.
Save justinwinslow/9b9629ea7221ec08b177 to your computer and use it in GitHub Desktop.
localStorage in angular
// Grab or create stored data
$scope.localData = JSON.parse(localStorage.getItem('localData')) || {};
// Watch for items to change and update data in localStorage
$scope.$watch('localData', function(localData, oldLocalData){
if (localData != oldLocalData) {
localStorage.setItem('localData', JSON.stringify($scope.localData));
}
}, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment