angular-stored-object
Local resource support for Angular using HTML5 storage
Combines the best of ngResource, ngStorage and angular-local-storage to give you access to local and session storage within Angular, but also provides a storage strategy that supports sharing sessionStorage data between multiple tabs via transient localStorage use.
Installation
Using NPM:
npm install --save angular-stored-object
Using Bower:
bower install --save angular-stored-object
API
The small API is fully documented.
Example
A session service consists of an object that when stored will be identified via the prefixed key 'session':
angular ; angular ; { return 'session'; }
An auth service manipulates the properties of the session object and calls $create and $delete as needed to persist to/delete from storage. $update, not shown, can be used when the token needs to be refreshed.
angular ; { var _redirectToState = null; var _redirectToParams = null; return login: login isLoggedIn: isLoggedIn logout: logout registerRedirect: registerRedirect followRedirect: followRedirect ; { return $http; } { return !!sessiontoken; } { session; $state; } { _redirectToState = toState; _redirectToParams = toParams; } { if _redirectToState $state; _redirectToState = _redirectToParams = null; else $state; }
For completion, the run block:
angular ; { $rootScope; $rootScope; { if toStatename === 'login' && auth event; auth; if toStatedata && toStatedataauthenticate && !auth event; auth; $state; } { ; } }
And the routes:
angular ; { $stateProvider ; $urlRouterProvider; }