LibStorageService
LocalStorage service for Angular projects to watch, detect LocalStorage changes
Install
npm install lib-storage-service
Usage
In your app.module.ts
(or any module.ts file):
;
then:
In your components:
;;
Functions
setItem()
Use this method to set item in LocalStorage
and notify observers.
Usage:
storageService.setItemkey, value;
removeItem()
Use this method to remove item from LocalStorage
and notify observers.
Usage:
storageService.removeItemkey;
clear()
Use this method to remove all item from LocalStorage
and notify observers.
Usage:
storageService.clear;
watchStorage()
Usage:
storageService.watchStorage.subscribe;
Example
Detect the token
key changes in LocalStorage
. If token goes to empty we call authService.logout()
method:
storageService.watchStorage.subscribe;