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 - And Import via
import { StorageModule } from '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: 'keyofdata', value: res })
NB: data format that accepted by setData
method is
export interface dataFormat {
key: string
value?: any
}
Getting Data
Use getData
method to retrive data, and it intake key as argument
eg:this.StorageService.getData('key_of_data')
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')
removeAllthis.StorageService.removeAll()
Browsers support
IE / Edge | Firefox | Chrome | Vivaldi |
---|
IE11, Edge | last 8 versions | last 8 versions | last 2 versions |