Namespaced client storage for Angular JS. Writes to localStorage, with cookie fallback.
No external dependencies other than Angular core; does not depend on ngCookies
.
To get started, add taggedClientStorage-min.js
to your webpage:
<script type="text/javascript" src="path/to/taggedClientStorage-min.js"></script>
And add the module tagged.services.client-storage
to your app's dependencies:
var app = angular.module('MyApp', ['tagged.services.client-storage']);
Then inject the taggedClientStorage
factory into your app.
app.controller('MyController', function($scope, taggedClientStorage) {
var myStorage = taggedClientStorage('my_namespace');
myStorage.set('foo', 'bar'); // stores `foo` with value `"bar"` under namespace `my_namespace`
myStorage.get('foo'); // returns `"bar"`
// Types are maintained
myStorage.set('count', 123); // store an `int`
myStorage.get('count') === 123; // get back an `int`
});
- AngularJS 1.2.x (Tested with 1.2.21)
- RequireJS (Optional)
This service can be loaded as an AMD module if you're using RequireJS. There are a few requirements:
- You must add paths to
angular
in your RequireJS config. - You must shim
angular
to exportangular
.
At minimum, your requirejs config must include this:
requirejs.config({
paths: {
'angular': 'path/to/angular'
},
shim: {
'angular': {
'exports': 'angular'
}
}
});
Once configured, you can require()
the original source file src/taggedClientStorage
in your app:
define(['angular', 'path/to/src/taggedClientStorage'], function(angular) {
var app = angular.module('MyApp', ['tagged.services.clientStorage']);
/* ... */
});
Requirements
- nodejs 1.10.x
- npm 1.2.32
To set up the development environment, run these commands once:
# Global dependencies
$ npm install --global grunt-cli bower
# Local node dependencies (Karma, etc.)
$ npm install
# 3rd-party libraries (Angular, etc.)
$ bower install
Running Tests Once the development environment has been set up, tests can be run in a number of ways:
# Run all tests once
$ grunt test
# Run tests in development mode (enables file watcher to automatically rerun tests)
$ grunt dev
Building Production Files
# Build production files in `./`
$ grunt build
Contributions welcome! All we ask is that pull requests include unit tests. Thanks!
Copyright 2014 Tagged, Inc.