Store Service
The Store Service (CloudAppStoreService
) provides capabilities to save and retrieve data which is stored in the browser’s local storage. The service wraps the browser’s local IndexedDB service, but provides isolation between different Cloud Apps. The following methods are available:
get
This method is used to retrieve stored data by key.
Interface
get(key: string): Observable<any>
Parameters:
- Key: string which represents the key used to store the data
Example
import { CloudAppSettingsService } from '@exlibris/exl-cloudapp-angular-lib'; export class MainComponent implements OnInit, OnDestroy { private content: any; constructor( private storeService: CloudAppStoreService ) { } ngOnInit() { this.storeService.get('content') .subscribe(content => this.content = content); } }
set
This method is used to store the data according to the specified key
Interface
set(key: string, value: any): Observable<any>
Parameters:
- Key: string which represents the key used to store the data
- Value: the data to be stored
Example
save() { this.storeService.set('content', 'this is my content') .subscribe(() => console.log('saved'); }
Note that a Cloud App’s stored values are stored in a single entry in the browser’s IndexedDB. If you have to set multiple values you should call the
set
method sequentially rather than in parallel to avoid unpredictable behavior.remove
This method is used to remove the data specified by the key.
Interface
remove(key: string): Observable<any> {
Parameters:
- Key: string which represents the key used to store the data
Example
remove() { this.storeService.remove('content') .subscribe(response => console.log('Removed')); }