An AngularJS module that makes Web Storage working in the Angular Way. Contains two services:
Differences with Other Implementations
sessionStorage - We got this often-overlooked buddy covered.
Cleanly-Authored Code - Written in the Angular Way, well-structured with testability in mind.
Require ngStorage and Inject the Services
Read and Write | Demo
$sessionStorage) by reference to a hook under
And use it like you-already-know:
Optionally, specify default values using the
With this setup, changes will be automatically sync'd between
$localStorage, and localStorage - even across different browser tabs!
Read and Write Alternative (Not Recommended) | Demo
If you're not fond of the presence of
$scope.$storage, you can always use watchers:
This, however, is not the way ngStorage is designed to be used with. As can be easily seen by comparing the demos, this approach is way more verbose, and may have potential performance implications as the values being watched quickly grow.
Delete | Demo
This will delete the corresponding entry inside the Web Storage.
Delete Everything | Demo
If you wish to clear the Storage in one go, use the
Optionally, pass in an object you'd like the Storage to reset to:
Permitted Values | Demo
You can store anything except those not supported by JSON:
NaN- Will be replaced with
undefined, Function - Will be removed.
$ npm install to install dependencies. Then run
$ grunt for minification.
- ngdoc Documentation
- Namespace Support
- Unit Tests
- Grunt Tasks
Any contribution will be appreciated.