angular-web-storage
TypeScript icon, indicating that this package has built-in type declarations

19.0.0 • Public • Published

angular-web-storage

Angular decorator to save and restore of HTML5 Local&Session Storage

NPM version Ci

Demo

1、Usage

install angular-web-storage from npm

npm install angular-web-storage --save

2、Examples

  1. using LocalStorage or SessionStorage 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}`;
}
  1. using LocalStorageService or SessionStorageService 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:

  1. Use GitHub Issues board to report bugs and feature requests (not our email address)
  2. 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)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
19.0.0461latest
17.0.0-rc.01next

Version History

VersionDownloads (Last 7 Days)Published
19.0.0461
18.0.0174
17.0.01,370
17.0.0-rc.01
16.0.0282
15.0.0132
14.0.0588
13.0.061
12.0.059
10.0.0371
9.0.0255
9.0.0-rc.10
7.0.0-beta.1605
4.1.0226
4.0.01
3.0.021
3.0.0-beta.10
2.0.02
2.0.0-beta.11
1.0.11
1.0.00

Package Sidebar

Install

npm i angular-web-storage

Weekly Downloads

4,611

Version

19.0.0

License

MIT

Unpacked Size

25.2 kB

Total Files

9

Last publish

Collaborators

  • cipchk