@lkmylin/angular-statemanager v1.0.2
angular-statemanager
This project was generated with Angular CLI version 1.6.4
and packaged using ng-packagr version 2.4.2. It provides
an injectable class (service) that can be used in Angular projects to keep track of state in HTML controls,
e.g. the current page of a data grid. It uses window.localStorage
to cache state data, so it won't work
in browsers that don't support localStorage (but it won't break anything).
Installation
npm install @lkmylin/angular-statemanager
Implementation
In your bootstrap module:
import { StateManagerModule, StateManager } from "@lkmylin/angular-statemanager";
add
StateManager
to your providersadd
{provide: "window", useValue: window}
to your providersinject an instance where needed
use
stateManager.SetValue(id, property, value)
to cache a valueid
is the control's unique IDproperty
is the key for the property/attribute you want to cache, e.g.currentPage
value
is the object you want to cache
use
stateManager.GetValue(id, property, defaultValue)
to retrieve a value from the cacheid
is the control's unique IDproperty
is the key for the property/attribute you want to retrieve, e.g.currentPage
defaultValue
is the default value to return in case the id:property pair you are looking for isn't cached or the user has cleared their browsing history, etc.
if you want to see the entire contents of the cache, use
stateManager.CurrentState