Store Service

The Store Service (CloudAppStoreService) provides capabilities to save and retrieve data which is stored in the browser’s local storage. 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');
}

 

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 => {
      this.toastr.success('Settings successfully saved.');
    }
  );
}