ng-storage
A better way to store data in browser without cookies,
NB:we relies on session and data wont get cleared on refresh but tab close will clear all data
Usage
- Run
npm i ng-storage --save
to add module to project - Add
import { StorageModule } from 'ng7-storage';
in App Module - Add to imports
imports: [
BrowserModule,
StorageModule
],
Setting Data
Please note that we have to pass key value pairs to service , and key should be string and do not pass value as json string
this.StorageService.setData({ key: 'key_of_data', value: res ,encrypt:optional|boolean})
NB: data format that accepted by setData
method is
export interface dataFormat {
key: string;
value?: any;
encrypt?: Boolean;
decrypt?: Boolean;
}
Getting Data
Use getData
method to retrieve data, and it intake key as argument
eg:this.StorageService.getData({key: 'key_of_data',decrypt:optional|boolean})
Remove Data
removeData
method is used remove single item based on keyremoveAll
method remove all data stored
Examples :
removeData : this.StorageService.removeData('key_of_data')
removeAll : this.StorageService.removeAll()
Available methods
setData()
getData()
removeData()
removeAll()
Browsers support
IE / Edge | Firefox | Chrome | Vivaldi |
---|
IE11, Edge | last 8 versions | last 8 versions | last 2 versions |
Built with 🔧
- HTML - For the web framework
- CSS - For styling components
- JavaScript - For magic!
- Angular - To add to the JavaScript magic!
Developing 👷
- Clone this repo with git.
- Install dependencies by running
npm install
within the directory that you cloned (probably ng-storage
). - Start the development server with
ng serve --o
. - Open development site by going to http://localhost:4200 in your browser.
Author 🔮