https://github.com/netanelbasal/angular2-storage-sync
Angular2 decorator to sync properties automatically from/to LocalStorage or SessionStorage
https://github.com/netanelbasal/angular2-storage-sync
Last synced: 8 months ago
JSON representation
Angular2 decorator to sync properties automatically from/to LocalStorage or SessionStorage
- Host: GitHub
- URL: https://github.com/netanelbasal/angular2-storage-sync
- Owner: NetanelBasal
- Created: 2016-10-05T10:29:49.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-18T05:54:56.000Z (over 8 years ago)
- Last Synced: 2024-10-30T06:32:43.564Z (over 1 year ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deprecated! Do Not Use!
### Angular2 Storage Sync
The Angular2 Storage Sync is an Angular2 decorator to sync properties automatically from/to LocalStorage or SessionStorage.
#### Use
1. `cd` to the root of your app and run `npm install --save angular2-storage-sync`
OR add `"angular2-storage-sync": "^0.1.0"` to your package.json file and then `cd` to the root of your app and run `npm install`
2. Use in your component or service:
```typescript
import { StorageSync, StorageStrategy } from 'angular2-storage-sync';
export class AppComponent {
@StorageSync('rememberMe') remember: boolean = false;
@StorageSync(null, StorageStrategy.Session) items: Array = [];
}
```
##### The @StorageSync decorator expects two params:
1. Custom key - the default is the property name.
2. StorageStrategy - Local or Session - defaults to LocalStorage.
**Important**:
Always define a default value for the properties you are using in the `@StorageSync` lines.
##### Example
```javascript
@Component({
selector: 'storage-app',
template:
Remember me
Set items
-
{{item.id}}
})
export class AppComponent {
@StorageSync('rememberMe') remember: boolean = false;
@StorageSync(null, StorageStrategy.Session) items: Array = [];
setItems() {
// To store data, set this.items (the variable of type Array in your @StorageSync call)
//equal to whatever you want to store in local storage.
this.items = [{id: 1}, {id: 2}];
}
}
``