Angular Local Storage 使用方法

JS Example
var YourCtrl = function($scope, localStorageService, ...) {
  // To add to local storage
  localStorageService.set('localStorageKey','Add this!');
  // Read that value back
  var value = localStorageService.get('localStorageKey');
  // To remove a local storage
  localStorageService.remove('localStorageKey');
  // Removes all local storage
  localStorageService.clearAll();
  // You can also play with cookies the same way
  localStorageService.cookie.set('localStorageKey','I am a cookie value now');
}

API Access

CallArgumentsActionReturns
isSupportedn/aChecks the browsers support for local storageBoolean for success
setkey, valueAdds a key-value pair to the browser local storageBoolean for success
getkeyGets a value from local storageStored value
removekey, ...Removes a key-value pairs from the browser local storagen/a
clearAlln/aWarning Removes all local storage key-value pairs for this app. It will optionally take a string, which is converted to a regular expression, and then clears keys based on that regular expression.Boolean for success
cookieset | get | remove | clearAllEach function within cookie uses the same arguments as the coresponding local storage functionsn/a