angular-local-storage-ci-dev
An Angular module that gives you access to the browsers local storage
A forked version for our project CI, add new features such as expiry support for localStorage and so on to meet our demand.
Install
$ npm install angular-local-storage-ci-dev
var angularLocalStorage = ; angular;
Configuration
setPrefix
You could set a prefix to avoid overwriting any local storage variables from the rest of your app
Default prefix: ls.<your-key>
myApp;
setStorageType
You could change web storage type to localStorage or sessionStorage
Default storage: localStorage
myApp;
setStorageCookie
Set cookie options (usually in case of fallback)
cookieOptions: options
cookieOptions.path the web path the cookie represents. default: '/'
myApp;
setNotify
Configure whether events should be broadcasted on $rootScope for each of the following actions:
setItem , default: true
, event "LocalStorageModule.notification.setitem"
removeItem , default: false
, event "LocalStorageModule.notification.removeitem"
myApp;
Configuration Example
Using all together
myApp;
API Documentation
isSupported
Checks if the browser support the current storage type(e.g: localStorage
, sessionStorage
).
Returns: Boolean
myApp;
getStorageType
Returns: String
myApp;
set
Directly adds a value to local storage.
If local storage is not supported, use cookies instead.
Returns: Boolean
myApp;
get
Directly get a value from local storage.
If local storage is not supported, use cookies instead.
Returns: value from local storage
myApp;
keys
Return array of keys for local storage, ignore keys that not owned.
Returns: value from local storage
myApp;
remove
Remove an item(s) from local storage by key.
If local storage is not supported, use cookies instead.
Returns: Boolean
myApp;
clearAll
Remove all data for this app from local storage.
If local storage is not supported, use cookies instead.
Note: Optionally takes a regular expression string and removes matching.
Returns: Boolean
myApp;
bind
Bind $scope key to localStorageService.
Usage: localStorageService.bind(scope, property, value[optional], key[optional])
key: The corresponding key used in local storage
Returns: deregistration function for this listener.
myApp;
{{property}} update unbind
deriveKey
Return the derive key
Returns String
myApp;
length
Return localStorageService.length, ignore keys that not owned.
Returns Number
myApp;
Cookie
Deal with browser's cookies directly.
cookie.isSupported
Checks if cookies are enabled in the browser.
Returns: Boolean
myApp;
cookie.set
Directly adds a value to cookies.
Note: Typically used as a fallback if local storage is not supported.
Returns: Boolean
myApp;
Cookie Expiry Pass a third argument to specify number of days to expiry
localStorageServicecookie
sets a cookie that expires in 10 days.
cookie.get
Directly get a value from a cookie.
Returns: value from local storage
myApp;
cookie.remove
Remove directly value from a cookie.
Returns: Boolean
myApp;
cookie.clearAll
Remove all data for this app from cookie.
Returns: Boolean
myApp;