Socket
Socket
Sign inDemoInstall

angular2-storage-sync

Package Overview
Dependencies
13
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular2-storage-sync

Angular2 decorator to sync properties automatically from/to LocalStorage or SessionStorage


Version published
Maintainers
1
Install size
15.4 MB
Created

Readme

Source

Angular2 Storage Sync

Angular2 decorator to sync properties automatically from/to LocalStorage or SessionStorage

Use

  1. npm install --save angular2-storage-sync
  2. Use in your component:
import { StorageSync, StorageStrategy } from 'angular2-storage-sync';

export class AppComponent {
 @StorageSync('rememberMe') remember: boolean = false;
 @StorageSync(null, StorageStrategy.Session) items: Array<Object> = [];
}

The @StorageSync expects two params:

  1. Custom key - the default is the property name.
  2. StorageStrategy - Local or Session - default to LocalStorage.

Important: Define always a default value at the property you are using @StorageSync.

Example

@Component({
  selector: 'storage-app',
  template: 
    <input type="checkbox"  [(ngModel)]="remember"> Remember me
    <button (click)="setItems()">Set items</button>
    <ul>
      <li *ngFor="let item of items">
       {{item.id}}
      </li>
    </ul>
})

export class AppComponent {
  @StorageSync('rememberMe') remember: boolean = false;
  
  @StorageSync(null, StorageStrategy.Session) items: Array<Object> = [];

  setItems() {
    // this is always sync with your storage
    this.items = [{id: 1}, {id: 2}];
  }
}
``

Keywords

FAQs

Last updated on 05 Oct 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc