- returns $q promises
- works in the browser with local storage
$ bower install ng-persist ngstorage --save
For ios, KeychainPlugin is required:
$ cordova plugin add https://github.com/shazron/KeychainPlugin.git
For Android, cordova-plugin-file is required:
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
Require ng-persist and ngstorage
angular.module('myApp', [
'ngStorage',
'ng-persist'
]);
Inject $persist
into your controller
.controller('MyCtrl', function($persist) {
// write
$persist
.set(namespace, key, val)
.then(function () {
// saved
});
// read
$persist
.get(namespace, key, fallback)
.then(function (val) {
// val is either the value, if exists, or the fallback
});
// delete
$persist
.remove(namespace, key)
.then(function () {
// removed
});
});
MIT