@egt-ukraine/storage
v1.3.1
Published
Angular wrapper for [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage), [sessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage).
Downloads
156
Readme
EGT Storage Module
Angular wrapper for localStorage, sessionStorage.
How to use?
Install:
npm i @egt-ukraine/storage
or yarn add @egt-ukraine/storage
import { NgModule } from '@angular/core';
import { StorageModule } from '@egt-ukraine/storage';
@NgModule({
imports: [
StorageModule.forRoot(),
],
exports: [],
declarations: [],
})
export class CoreModule {}
Usage:
import { Injectable } from '@angular/core';
import { IWindowStorage, StorageRegistry } from '@egt-ukraine/storage';
@Injectable()
export class SomeService {
private _storage: IWindowStorage;
private _storageObjectKey: string = 'my-cool-variable-from-local-storage';
private _storageType: string = 'local';
constructor(private _storageRegistry: StorageRegistry) {
this._storage = this._storageRegistry.getStorage(this._storageType);
}
public setSomeValue(someValue: string): void {
this._storage.set(this._storageObjectKey, someValue);
}
public getSomeValue(): string {
return this._storage.get(this._storageObjectKey);
}
}