1.0.3 • Published 5 years ago
ngx-storage-api v1.0.3
ngx-storage-api is a simple wrapper above localStorage and sessionStorage in a shape of Angular services.
Play with a live demo in this stackblitz
Installation
To use ngx-storage-api in your project install it via npm:
npm i ngx-storage-apior using yarn:
yarn add ngx-storage-apiUsage
In order to use localStorage or sessionStorage inject the desired service:
import { LocalStorageService, SessionStorageService } from 'ngx-storage-api';
@Component({
selector: 'app-my-component',
template: ``,
styles: [],
})
export class MyComponent implements OnInit {
constructor(
private readonly localStorageService: LocalStorageService,
private readonly sessionStorageService: SessionStorageService
) {}
ngOnInit(): void {
this.localStorageService.clear();
this.localStorageService.setItem('hello', 'world');
this.localStorageService.getItem('hello');
this.localStorageService.removeItem('hello');
this.localStorageService.localStorage$.subscribe((e: StorageEvent) => {
console.log('localStorage changed!', e);
});
}
}