ng2-chrome-storage
Chrome extensions storage API simplified for Angular 2.
- The storage API is mostly used for providing app settings to extensions's end users. e.g. In your weather extension, ask user for his location etc.
- ng2-chrome-storage makes settings available to your components by a simple API, they are loaded before anything is initialized.
- Developer friendly: Your extensions will work on your local environment as well by making use of browser's
localStorage
.
Setup
Create your own settings.class.ts
file to represent the default settings:
; ;
In you main app module add Ng2ChromeStorageModule
and pass your default settings to it:
;;
That is it! Rest is handled by the module.
Usage
Now simply use ChromeStorage
service. It's config
property holds the settings.
Example component:
;;
Subscribe to Change detection:
ngOnInit
Your App's Settings Page
Example form component:
;;;
API
Properties:
storeKey:
Set the key name to be used for main storage.
config:
Holds the settings.
Methods:
-
setAll(settings: Object, key = this.storeKey): Promise<boolean>
Save an object to the storage. -
getChrome(key: string, defaults = {}): Promise<any>
Get object with a specific key and defaults. -
onChange(key = this.storeKey): Observable<any>
Change detection on storage. Changes will be availabe in thedata
param of the subscribe method. -
remove(key: string): Promise<boolean>
Remove a specific object by key. -
clear(): Promise<boolean>
Clear all the storage.