ng-local-storage
AngularJS friendly wrapper for the LocalStorage API.
Install
Install with npm if using Browserify:
Using NPM
npm install ng-local-storage --save
Using a Manual Build
Alternatively clone this repo and run:
npm i
npm run build
Once finished the dist folder will contain a file you can include in your project.
Usage & Example
Simply add ngLocalStorage as a dependency of your project.
angular ;
API
Internally this module uses browser-ls so any function it exposes is exposed by this Angular service with two small differences.
Difference #1
You must always use the getAdapter function to get an instance as methods aren't bound directly to the service object.
Difference #2
Callbacks aren't supported. Instead the library will return promises for all functions except getAdapter. So in browser-ls you might do this:
{ ls; }
With ng-local-storage the above code becomes:
{ // Return the promise! return ls;}
Functions
getAdapter (name)
This will get a localStorage interface that stores data under the given key name to avoid clashes.
All of the following methods return a promise.
get(key)
Get a string value from localStorage.
getJson(key)
Get an Object from localStorage.
set(key, string)
Set a string value in localStorage.
setJson(key, object)
Write a JSON object to localStorage.
remove(key)
Remove an object from localStorage.
Contributing
Follow the existing style (there's a .editorconfig so it's easy) and create a PR. Add tests if required.