0.0.3 • Published 7 years ago
ng2modules-storage v0.0.3
ng2modules-storage
Local and session storage for Angular 2.
Install
npm i ng2modules-storage
Browser Support
This library makes heavy use of ES6 Proxy, meaning it only has support in the latest Edge, Chrome, Firefox, and Opera.
Usage
First, import the module to the root module:
import { StorageModule } from 'ng2modules-storage';
// In your app's root module
imports: [
StorageModule.forRoot({prefix: 'ng2-storage'})
]
Next, inject it into a component:
import { StorageService } from 'ng2modules-storage';
@Component({
template: `<button (click)="incrementStoredData()">click</button>`
})
export class MyComponent {
public storage: any;
constructor(storage: StorageService) {
// you can also use storage.session for sessionStorage
this.storage = storage.local;
}
incrementStoredData() {
this.storage.data = this.storage.data || 0;
this.storage.data++;
}
}
Options
Name | Default | Description |
---|---|---|
prefix | 'ng2-storage' | The key prefix when assigning data to local or session storage. |
serialize | window.JSON | Used when de/serializing data from the storage container. Both serialize and parse attributes must be specified and must be functions if you want custom ones. |