angular-forage
A Angular service module for localForage
Installation
Simply install the npm package angular-forage
:
NPM
npm i localforage object-path angular-forage
YARN
yarn add localforage object-path angular-forage
Using angular-forage
In your main app module file (eg. app.module.ts
):
;; ; ; @ {}
In your components:
;; @ title = 'app'; { thisaf; // this.af.setIndexedDBDriver(); // this.af.setWebSQLDriver(); thisaf; } { // SET ITEM // this.af.setItem('key', 'value'); thisaf; // or thisaf; // GET ITEM // this.af.getItem('key''); thisaf; // REMOVE ITEM // this.af.removeItem('key''); // this.af.removeItem('app'); // this.af.clear(); // delete everything // Forage will stringify/parse the json object automatically. }
All the methods will return promise. Use .then()
and .catch()
whereever you need.
- Please refer to localForage documentation for more info, you can view the localForage Docs at https://localforage.github.io/localForage
Default Driver
By default, localForage selects backend drivers for the datastore in this order:
- IndexedDB
localforage.INDEXEDDB
- WebSQL
localforage.WEBSQL
- localStorage
localforage.LOCALSTORAGE
If you would like to force usage of a particular driver then set driver as this.af.setLocalStorageDriver();
this.af.setIndexedDBDriver();
this.af.setWebSQLDriver();
API will work same as localForage in your app with this.af
, only the json has been added to update json objects easily.
You can use . notation for json object, if you need to update the version in above app code then you can simple
thisaf;
and to update author name
thisaf;
json will resolve with main object, in above example code .then(value => console.log(value))
will log the updated app
object.
Contributing
Any sort of contributions and feedback is much appreciated. Just leave an issue or pull-request!