Other Methods

The SDK provides other methods which can help you in your development of Cloud Apps. The following modules are available:

FormGroupUtil

The FormGroupUtil module supports the creation of Angular Reactive Forms. As an alternative to using the FormBuilder API to create a new reactive form, you can use the toFormGroup method which returns a FormGroup.

toFormGroup

Interface

toFormGroup(obj: Object): FormGroup

Parameters:

  • Any object

Returns: FormGroup

Example

Using the pattern below provides the following benefits:

  • A class with default values defined
  • A method to create the FormGroup which merges a new object with the existing object, thereby handling any new values added to the class
  • A component which loads the object and passes it to the toFormGroup method
import { FormGroupUtil } from "@exlibris/exl-cloudapp-angular-lib";
import { merge } from 'lodash';

export class Configuration {
  restProxyUrl: string = "";
  existingLicense: boolean = false;
}

export const configurationFormGroup = 
   (config: Configuration) => FormGroupUtil.toFormGroup(merge(new Configuration(), config));
import { Component, Injectable, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { configurationFormGroup } from '../models/configuration';
import { ConfigurationService } from '../services/configuration.service';

@Component({
  selector: 'app-configuration',
  templateUrl: './configuration.component.html',
  styleUrls: ['./configuration.component.scss']
})
export class ConfigurationComponent implements OnInit {

  form: FormGroup;
  
  constructor(
    private configurationService: ConfigurationService,
  ) { }

  ngOnInit() {
    this.configurationService.get().subscribe(configuration => {
      this.form = configurationFormGroup(configuration);
    });
  }