Skip to content

Instantly share code, notes, and snippets.

@Baudin999
Created November 27, 2013 20:35
Show Gist options
  • Save Baudin999/7682768 to your computer and use it in GitHub Desktop.
Save Baudin999/7682768 to your computer and use it in GitHub Desktop.
Chrome App Storage, retrieving and saving
// When getting somehting from the chrome storage you
// need to keep in mind that these items are returned
// as objects compared to the localStorage in the browser
// which returns the items als string literals.
// In combination with angularJS you need to keep in mind
// that you need to apply the result of this async call
// the the $scope of the controller. This will trigger
// the refresh.
// I use the chrome storage sync, but there is also a
// chrome storage local.
chrome.storage.sync.get('firstName', function(person) {
$scope.$apply(function() {
$scope.voornaam = person.firstName;
});
});
if ($scope.firstName) {
chrome.storage.sync.set({ firstName: $scope.firstName }, function(){
console.log('first name saved to storage');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment