@shaaakh/ngx-webstorage
v1.0.0
Published
Angular 9+ decorator to save and restore of HTML5 Local&Session Storage
Downloads
6
Readme
angular-web-storage
Angular decorator to save and restore of HTML5 Local&Session Storage
Version
- Angular 9
1.x
1、Usage
install @shaaakh/ngx-webstorage
from npm
npm install @shaaakh/ngx-webstorage --save
Import the AngularWebStorageModule
in your module.
import { AngularWebStorageModule } from 'angular-web-storage';
@NgModule({
imports: [
BrowserModule,
AngularWebStorageModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
2、Examples
- using
LocalStorage
orSessionStorage
decorator.
import { Component } from '@angular/core';
import { LocalStorageService, SessionStorageService, LocalStorage, SessionStorage } from 'angular-web-storage';
@Component({
selector: 'demo',
templateUrl: './demo.component.html'
})
export class DemoComponent {
@LocalStorage() localValue: Object = { text: `Hello ${+new Date}`};
// Set storage key and expire after 10 hours
@LocalStorage('newKey', 10, 'h') localValue2: Object = { text: `Hello ${+new Date}`};
@SessionStorage() sessionValue: string = `Hello ${+new Date}`;
}
- using
LocalStorageService
orSessionStorageService
service.
import { Component } from '@angular/core';
import { LocalStorageService, SessionStorageService, LocalStorage, SessionStorage } from 'angular-web-storage';
@Component({
selector: 'demo',
templateUrl: './demo.component.html'
})
export class DemoComponent {
constructor(public local: LocalStorageService, public session: SessionStorageService) { }
KEY = 'value';
value: any = null;
set(expired: number = 0) {
this.local.set(this.KEY, { a: 1, now: +new Date }, expired, 's');
}
remove() {
this.local.remove(this.KEY);
}
get() {
this.value = this.local.get(this.KEY);
}
clear() {
this.local.clear();
}
}
Expired Time Unit
s
Second.m
Minute.h
Hour.d
Day.w
Week(equar 7 Day).y
Year.t
Custom(unit: millisecond).
Troubleshooting
Please follow this guidelines when reporting bugs and feature requests:
- Use GitHub Issues board to report bugs and feature requests (not our email address)
- Please always write steps to reproduce the error. That way we can focus on fixing the bug, not scratching our heads trying to reproduce it.
Thanks for understanding!
License
The MIT License (see the LICENSE file for the full text)