Angular2 @LocalStorage
This little Angular2/typescript decorator makes it super easy to save and restore automatically a variable state in your directive (class property) using HTML5' LocalStorage.
Use
- Download the library using npm or github:
npm install angular2-localstorage-annotation
- Register the LocalStorage in your boot.ts:
; // register LocalStorage, this registers our change-detection.;LocalStorageSubscriberappPromise;
- Use the
LocalStorage
decorator
;
Note: Define always a default value at the property you are using @LocalStorage
.
Note: The localStorage key is per default the property name. Define the first argument of @LocalStorage
to set different one.
Examples