19.0.0 • Published 5 months ago
angular-web-storage v19.0.0
angular-web-storage
Angular decorator to save and restore of HTML5 Local&Session Storage
Demo
1、Usage
install angular-web-storage
from npm
npm install angular-web-storage --save
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}`};
// 设置存储KEY,以及10个小时后过期
@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(private local: LocalStorageService, private 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)
19.0.0
5 months ago
18.0.0
11 months ago
17.0.0-rc.0
2 years ago
17.0.0
1 year ago
16.0.0
2 years ago
15.0.0
2 years ago
14.0.0
3 years ago
13.0.0
3 years ago
12.0.0
4 years ago
10.0.0
5 years ago
9.0.0-rc.1
5 years ago
9.0.0
5 years ago
7.0.0-beta.1
6 years ago
4.1.0
6 years ago
4.0.0
7 years ago
3.0.0
7 years ago
3.0.0-beta.1
7 years ago
2.0.0
7 years ago
2.0.0-beta.1
7 years ago
1.0.1
8 years ago
1.0.0
8 years ago