Settings Service
The Settings Service (CloudAppSettingsService
) provides capabilities to save and retrieve app-specific per-user settings. The settings are stored in Alma. The following methods are available:
get
This method is used to retrieve settings for the application and user.
Interface
get(): Observable<any>
Parameters:
- None
Example
import { CloudAppSettingsService } from '@exlibris/exl-cloudapp-angular-lib'; export class MainComponent implements OnInit, OnDestroy { private settings: any; constructor( private settingsService: CloudAppSettingsService ) { } ngOnInit() { this.settingsService.get().subscribe( settings => this.settings = settings ); } }
set
This method is used to set the settings for the application and user.
Interface
set(value: any): Observable<WriteSettingsResponse>
Parameters:
- Value: the data to be stored
Example
save() { this.settingsService.set(this.form.value).subscribe(response=>console.log('Saved')); }
remove
This method is used to remove the settings for the user and application.
Interface
remove(): Observable<WriteSettingsResponse>
Example
remove() { this.settingsService.remove().subscribe( () => console.log('removed') ); }
getAsFormGroup
This method is used to retrieve settings for the application and user as a FormGroup
which can be used in Reactive Forms.
Interface
getAsFormGroup(): Observable<FormGroup>
Example
import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { CloudAppSettingsService } from '@exlibris/exl-cloudapp-angular-lib'; @Component({ selector: 'app-settings', templateUrl: './settings.component.html', styleUrls: ['./settings.component.scss'] }) export class SettingsComponent implements OnInit { form: FormGroup; constructor( private fb: FormBuilder, private settingsService: CloudAppSettingsService ) { } ngOnInit() { this.settingsService.getAsFormGroup().subscribe( settings => { if (Object.keys(settings.value).length!=0) { this.form = settings; } }); } }