Thursday, September 14, 2017

New Version of vadacl Released as an NPM Package

It's been a LONG time since my last blog post.  Work and life simply kept me from doing a lot of personal coding.  But I'm making an effort to get back into the swing of things, and I decided to start that effort by moving forward with my vadacl Angular validation library.

For anyone not familiar with what vadacl is about, here's the current synopsis:

vadacl is a library that extends and enhances reactive form validation in Angular 4.x. It provides:

  • A mechanism for declaring validation logic within domain classes / data objects that can be reused in multiple components.
  • The ability to configure the text of validation failure messages as part of the domain class validation logic or within a global validation message object.
  • Helper methods for triggering validation and displaying validation results.
  • Additional validation methods beyond those provided by Angular 4.x, and the ability to extend the vadacl validation methods with custom methods in your project.
  • The new version of vadacl (currently version 1.0.10) is available as an NPM package at:

    https://www.npmjs.com/package/vadacl

    There is also a separate GitHub repo containing an Angular CLI-powered Angular 4.x app that demonstrates the use of vadacl in different scenarios:

    https://github.com/bcswartz/vadacl-demo

    As part of the transition to an NPM package, vadacl was refactored to allow you to extend or override the validation methods and messages without touching the library files themselves, using files specific to your project.  That will let you update to future versions of vadacl via npm without losing any of your custom code.  The new version was written for Angular 4.x and includes vadacl versions of the newest methods in Angular's Validators class:  min, max, and email.

    The new demonstration application is an updated version of the one still hosted on the old vadacl GitHub repo, and contains not only examples of the new validation methods, but also provides documentation about how to go about extending vadacl and an example of how you can swap out the global messages file with a different one (designed for a different audience or different language) during your build/deployment process.

    Friday, December 30, 2016

    Version 0.2.0 of vadacl Released

    I just released a new version of my vadacl validation library for Angular 2. The new release includes the following updates:

    • To match a recent change to the pattern Validator in Angular 2, vadacl's pattern validation method was updated to accept both string and RegExp pattern arguments.

    • A requiredTrue validation method was added to parallel the recently-added Angular requiredTrue Validator (used primarily for validating that a checkbox has been checked/set to true).

    • The applyCollectionRule() method was added to the Vadacl class. The new method is designed to be used instead of the applyRules() method when applying a single validation method to a FormGroup or FormArray.

    • Added three new validation methods specifically for FormGroup and FormArray validation:

      • totals: validates that the sum of the numeric values of the FormGroup or FormArray controls equals a certain amount.

      • equalValues: validates that all of the values of the FormControls within a FormGroup or FormArray are exactly equal. Useful for performing password confirmation.

      • withinTrueCount: validates that the number of FormControls within a FormGroup or FormArray with a value of Boolean true falls within a given range. Designed primarily to validate how many checkboxes are checked.

    • Added and updated demos to demonstrate the new validation methods.

    • Updated the demo codebase to Angular 2.4.1

    Tuesday, November 29, 2016

    Locale-Based Message Support Added to vadacl

    The latest release of my vadacl validation library for Angular 2 introduces a new feature:  locale-based error message configuration.

    Prior to this release, vadacl would allow you to configure the error message for a particular validation error condition for a particular object property in either the object-based validation settings or in the component responsible for the form controls.  And if you did not declare an error message in either of those places, the validation method would return a method-specific default error message from the Messages object.  So in the following (slightly-contrived) scenario:

    
    // app/vadacl/locale/messages-en.ts
    let Messages = {
      /* DEFAULT LOCALE VALIDATOR ERROR MESSAGES */
      required: 'A value is required',
      ...
    }
    
    
    // app/domain/user-profile.ts
    ...
    export class UserProfile implements Validatable {
      firstName: string = null;
      lastName: string = null;
      username: string = null;
      age: number = null;
      gender: string = null;
    
      validations: { [ index: string ] : PropertyValidations } = {
        firstName: {
           required: { message: 'Your first name is required.' }
        },
        lastName: {
           required: {}
        },
        username: {
           required: { message: 'Username is required.' }
        },
        age: {
           required: {}
        },
        gender: {
           required: {}
        }
      };
      ...
    }
    
    // app/forms/user-profile-form.component.ts
    ...
    export class UserProfileForm extends Vadacl implements OnInit {
      profileForm: FormGroup;
      userProfile: UserProfile;
      ...
    
      ngOnInit() {
        this.userProfile = new UserProfile();
    
        this.profileForm = new FormGroup({
          'firstName': new FormControl(
             this.userProfile.firstName,
             this.applyRules( this.userProfile, 'firstName' )
          ),
    
          'lastName': new FormControl(
             this.userProfile.lastName,
             this.applyRules( this.userProfile, 'lastName', { required: { message: 'Your last name is required.' } )
          ),
    
          'username': new FormControl(
             this.userProfile.username,
             this.applyRules( this.userProfile, 'username', { required: { message: 'Please enter a username.' } )
          ),
    
          'age': new FormControl(
             this.userProfile.age,
             this.applyRules( this.userProfile, 'age' )
          ),
    
          'gender': new FormControl(
             this.userProfile.gender,
             this.applyRules( this.userProfile, 'gender' )
          )
        });
      }
      ...
    }
    
    ...the validation error message for each UserProfile property in the UserProfileForm template that fails the required validation would be:
    • firstName: "Your first name is required."
    • lastName: "Your last name is required." (the message is provided during the FormControl instantiation)
    • username: "Please enter a username." (the component-level message overrides the object-level message)
    • age: "A value is required"
    • gender: "A value is required"

    Now vadacl provides the option to configure error messages for object properties in the Messages object rather than in the validation settings in the object. Refactoring the example above to use the new feature, the code would look like:

    
    // app/vadacl/locale/messages-en.ts
    let Messages = {
      /* DEFAULT LOCALE VALIDATOR ERROR MESSAGES */
      required: 'A value is required',
      ...
    
      /* LOCALE-BASED DOMAIN CLASS MESSAGES */
      UserProfile: {
        firstName: {
          required: 'First name is required.'
        },
        lastName: {
          required: 'Last name is required.'
        },
        username: {
          required: 'Username is required.'
        }
      }
      ...
    }
    
    // app/domain/user-profile.ts
    ...
    export class UserProfile implements Validatable { 
      ...
      validations: { [ index: string ] : PropertyValidations } = {
        firstName: { required: {} },
        lastName: { required: {} },
        username: { required: {} },
        age: { required: {} },
        gender: { required: {} }
      };
      ...
    }
    
    // app/forms/user-profile-form.component.ts
    ...
      'lastName': new FormControl(
        this.userProfile.lastName,
        this.applyRules( this.userProfile, 'lastName' )
      ),
    
      'username': new FormControl(
        this.userProfile.username,
        this.applyRules( this.userProfile, 'username', { required: { message: 'Please enter a username.' } )
      ),
    ...
    
    ...and the error messages would now be:
    • firstName: "First name is required."
    • lastName: "Last name is required."
    • username: "Please enter a username."
    • age: "A value is required"
    • gender: "A value is required"

    The validation message defaults to the message in the Messages object that matches the object / property / validation method combination. If a different message is defined for that property in the object validation settings (which ordinarily you wouldn't do if you wanted to use the locale-based messages in the Messages object) or in the component when configuring the FormControl, that other message would become the message value returned when validation fails.

    Configuring the validation messages in the Messages object allows you to keep all of the object-level messages in one place.  In theory, this should also give developers who need to perform internationalization the option of creating Messages objects for different languages and then altering which Messages file is imported into validation-methods.ts file as a build step prior to compiling the app.

    Friday, November 11, 2016

    vadacl: A Library For Streamlining Form Validation in Angular 2

    The initial version of my TypeScript-based vadacl library for performing form validation in Angular 2 is now available on GitHub.

    vadacl provides the following enhancements to the typical implementation of form validation via the reactive form classes (FormControl, FormGroup, FormArray, and FormBuilder):

    • Instead of configuring all of the validation in the component hosting the form, you can configure certain validations within the data object itself (validation rules that should remain consistent wherever the data object is used in your application), then add to or modify those validation rules in the component to create the final set of validations needed for a given form.

    • The vadacl validation methods add a "message" property to the metadata object returned when the form data fails validation.  This "message" property value is the message meant to be presented to the user, and can be configured and/or overridden at multiple levels:

      • The method level, via a set of default message values
      • The data object
      • The component level
    • The Vadacl class, whether used as a superclass for your component or as a service, provides methods for providing an array of validator methods to the FormControls in your form and for displaying the validation error "message" values in your template, removing the need to add multiple DOM elements with "ngIf" directives to display each kind of validation error or to add code to your component to gather and translate validation failures into error messages.

    vadacl is (currently) a small library contained in a single folder you can just drop into your Angular application. The GitHub repo contains that folder as part of a small Angular 2.1.1 application containing several working demos of vadacl in action.

    Enjoy!

    Tuesday, November 8, 2016

    Learning Angular 2: Implementing My vadacl Validation Library

    Version 0.0.7 of my sandbox GuildRunner Angular 2 application is a refactor of the sandbox Chapter form I created in the previous version.  I refactored the form, which uses Angular's reactive form classes (FormControl, FormGroup, FormArray, and FormBuilder) to use a small validation library I created called vadacl.

    The two main features of vadacl are:

    • It allows developers to set validation rules for the properties of a domain class at both the domain class level and the component level (because some validations are there to ensure the data can be persisted back to the server, and those validations should be set on the domain class so they are consistent throughout the application).

    • It gives developers the ability to set a "message" value that will be part of the metadata object returned from a validator when the data is invalid (which you can see in action in the refactored sandbox Chapter form).

    You can read more about vadacl in my blog post about the library and in the README file in the vadacl GitHub repo.

    Wednesday, October 5, 2016

    Learning Angular 2: Exploring Reactive Form Classes and Validators

    Version 0.0.6 of my sandbox GuildRunner Angular 2 application adds an example of using the reactive form and Validator classes provided by Angular 2.  The example was added to the sandbox collection of components rather than the main application, as I plan on taking what I learned from the exercise and expanding on it when I write the "real" forms.

    In my blog post regarding GuildRunner release 0.0.4, which was my take on handling validation for Angular template-driven forms, I incorrectly stated that the other approach to forms supported by Angular 2 was referred to as "dynamic forms."  That's not the case:  the documentation page I was referring to was about how to dynamically generate form inputs for a collection of model data, which is a scenario where using the reactive form classes makes a lot of sense.  The documentation page that gave me the correct name to the alternative to template-driven forms - reactive forms - was the page on form validation.

    In the reactive form style, you do not bind your form controls to your model data.  Instead, you bind them to the reactive form classes, which are:

    The most basic reactive form - a form with a single input - would be constructed with a single FormGroup containing a single FormControl for the form input.  So a reactive form containing a single text input (say a "name" field with an initial value of "Bob") would be coded in the component like so:

    
    /*
    Import the reactive form classes (your Angular module will also have to import the Angular ReactiveFormsModule)
    */
    import {FormControl, FormGroup } from '@angular/forms';
    ...
    export class MyReactiveFormComponent implements OnInit {
      myForm: FormGroup;
      
      ngOnInit() {
        this.myForm = new FormGroup( {
          'name': new FormControl( 'Bob' )
        } )
      }
    

    ...And the HTML template for the form would be written like so:

    
    <form [formGroup]="myForm">
      <input type="text" formControlName="name">
    </form>
    

    Note how the HTML form is connected to the FormGroup via the formGroup attribute, and how the text input is bound to the FormControl via the formControlName attribute: ngModel is not in play here.

    Form input validation is applied by adding validator functions to the FormControl: a FormControl takes either a single validator function or an array of validator functions as its second constructor argument. Making the name input in our example required with a minimum length of 2 characters is a simple matter of adding the necessary validator functions shipped with Angular 2 within the Validators class:

    
      ngOnInit() {
        this.myForm = new FormGroup( {
          'name': new FormControl( 'Bob', [ Validators.required, Validators.minLength(2) ] )
        } )
      }
    

    A validation check will occur anytime the value of the FormControl changes, whether that change is made via the UI or programmatically (which is an improvement over how the template-driven forms work).

    A FormGroup can contain any number of FormControl objects.  It can also contain additional FormGroups (sub-groups within the main FormGroup) and FormArrays which hold a collection of unnamed, iterable FormControls.  A single validator function can be attached to each FormGroup and FormArray, usually a custom validator function that performs a validation based on multiple form values.

    To try out these features, I created a form for updating certain properties of a Chapter domain class:

    • A text input for updating the chapter name.
    • A select box for selecting the guild the chapter belongs to.
    • A radio button for setting whether or not the chapter was the head chapter for the guild.
    • A series of checkboxes representing the defense measures used at the chapter location, represented in the Chapter domain class an array of defense measure ID values.
    In the component, I created a single method (called in ngOnInit) for instantiating the reactive form classes and for subscribing to the change event emitter:
    
    //sandbox/chapter-reactive-form/chapter-reactive-form.component.ts
    import { Chapter } from "../../domain/chapter";
    import { guilds } from "../../db/guilds";
    import { defenseMeasures } from "../../db/defense-measures";
    
    import {FormControl, FormGroup, FormArray, Validators, FormBuilder} from '@angular/forms';
    ...
    export class ChapterReactiveFormComponent implements OnInit {
    
      chapter: Chapter;
      defenseArray: any = []; //Populated by ngOnInit with an array of defenses
      guildArray: any = []; //Populated by ngOnInit with an array of guilds
      defenseBoxArray: FormArray;
      form: FormGroup;
      ...
      constructor( private formBuilder: FormBuilder ) { }
      ...
      buildForm() {
    
        //Create a custom Validator function for the defenses array
        function hasDefenses( formArray: FormArray) {
          let valid = false;
          for( let c in formArray.controls ) {
            if( formArray.controls[c].value == true ) { valid = true }
          }
          return valid == true ? null : { noDefenses: true }
        }
    
        //Construct and populate the defenses FormArray outside of the FormBuilder so we can populate it dynamically
        this.defenseBoxArray = new FormArray( [], hasDefenses );
        for( let d in this.defenseArray ) {
          this.defenseBoxArray.push( new FormControl(( this.chapter.defenses.indexOf( this.defenseArray[d].id ) > -1 )))
        }
    
        this.form = this.formBuilder.group( {
          'name': [ this.chapter.name, [
            Validators.required,
            Validators.minLength(4),
            Validators.pattern('[a-zA-Z]+')
          ] ],
          'guild': [ this.chapter.guildId, Validators.required ],
          'headChapter': [ this.chapter.headChapter, Validators.required ],
          'defenses': this.defenseBoxArray
        } );
    
        this.form.valueChanges
          .subscribe( data => this.checkFormValidity( data ) );
      }
    
    

    The hasDefenses() function definition is an example of how to create a custom validator function, which should either return null if validation passed or return an object literal that provides some context for why the validation failed. The function is then passed as the 2nd argument in the FormArray constructor.

    The rest of the FormGroup representing the form is created using the FormBuilder, which provides a less verbose way to instantiating the other reactive form classes. The final statement in the method subscribes to the valueChanges event emitted by the form anytime a form value is updated and ties that event to the execution of the checkFormValidity method which I'll touch on shortly.

    The HTML form controls that bind to these reactive form elements looks like this:

    
    <-- sandbox/chapter-reactive-form/chapter-reactive-form.component.html -->
    <form class="form-horizontal well well-sm" *ngIf="chapter" [formGroup]="form">
      ...
      <input id="name" type="text" class="form-control" formControlName="name">
      ...
      <select id="guild" class="form-control" formControlName="guild">
        <option [selected]="form.controls.guild.value == null" value="">-- Select --</option>
        <option *ngFor="let g of guildArray" [selected]="g.id == guild" [value]="g.id">{{g.name}}</option>
      </select>
      ...
      <input type="radio" formControlName="headChapter" name="headChapter" value="true" [checked]="form.controls.headChapter.value === true"> Yes   
      <input type="radio" formControlName="headChapter" name="headChapter" value="false" [checked]="form.controls.headChapter.value === false"> No
      ...
      <ul formArrayName="defenses"> <!-- Must set the formArrayName -->
        <li *ngFor="let def of form.controls.defenses.controls; let i = index">
          <input type="checkbox" formControlName="{{i}}" > {{defenseArray[i].label}}
        </li>
      </ul>
    

    A few things worth pointing out:

    • The "--Select--" option for the guild drop-down was something I added so that text was displayed in the select box when the current value was null. The control would work fine without it.
    • Setting the "checked" attribute on the radio buttons based on the current headChapter form control state was necessary in order to show the initial value.
    • When a form control belongs to either a sub-FormGroup or a FormArray (as in this case), you need to use the formGroupName or formArrayName as an attribute in an HTML element that encloses the HTML elements bound to the FormControls within the FormGroup or FormArray.

    As mentioned earlier, a validator function returns an object literal with context information about the validation problem when validation fails.  Those object literals need to be translated into appropriate error messages to display to the user.  So in a similar fashion to what I did with my template-driven form, I had to provide some translations in my component as well as a collection of arrays to hold the translated error messages:

    
    //sandbox/chapter-reactive-form/chapter-reactive-form.component.ts
      ...
      errMsgs: any = {
        name: [],
        guild: [],
        headChapter: [],
        defenses: []
      };
    
      translations: any = {
        name: {
          required: 'The name is required.',
          minlength: 'The name must be at least 4 characters long.',
          pattern: 'The name can only contain letters.'
        },
        guild: {
          required: 'Please select a guild.'
        },
        headChapter: {
          required: 'Please select either Yes or No.'
        },
        defenses: {
          noDefenses: 'The chapter must implement at least one defensive measure.'
        }
      };
    

    Note how each translation block consists of the name of the form control and an object literal whose properties names match up with the object literal keys returned by the validator functions (including the one returned by my custom hasDefenses() function).

    The checkFormValidity() function (executed when the form emits the event indicating a form value has changed) performs the work of examining the current validation errors generated by the reactive form controls and creating the proper user-appropriate error messages:

    
    /sandbox/chapter-reactive-form/chapter-reactive-form.component.ts
      ...
      checkFormValidity( data?: any ){
        for( let k in this.errMsgs ) {
          this.errMsgs[k] = [];
          if( this.form.controls[k].errors && this.form.controls[k].dirty ) {
            for( let e in this.form.controls[k].errors ) {
              if( this.translations[k][e] ) {
                this.errMsgs[k].push( this.translations[k][e] );
              }
            }
          }
        }
      }
    

    Note that the validation error translation only occurs when the invalid form control is in a "dirty" state:  like template-driven form HTML elements, each form control has status values denoting if the form control is pristine or dirty, valid or invalid, and untouched or touched.  Preventing the users from seeing any validation errors when the control is pristine is desirable when you have a form that may initially be empty:  you don't want to display an error on a required field before the user has entered any data.  However, there is a drawback:  if you do change a form value programmatically, the change will trigger a validation check on the form control but it won't change the control state to dirty.  The workaround for that is to manually mark the field as dirty prior to changing the value, as demonstrated in this method:

    
    changeName() {
      this.form.controls['name'].markAsDirty();
      this.form.controls['name'].setValue( '999' ); //invalid based on the [a-zA-Z]+ pattern validator
    }
    

    Flipping back to the HTML template, the user-appropriate error messages are displayed under the form controls like so:

    
    <div *ngIf="errMsgs.name.length" class="alert alert-danger">
      <ul>
        <li *ngFor="let error of errMsgs.name">
          {{error}}
        </li>
      </ul>
    </div>
    

    Another benefit to using the reactive form classes is that the FormGroup class comes with a reset() method that not only blanks/nulls out the targeted form control values, it also resets the form controls back to a pristine and untouched state.

    The final piece of the puzzle was to write a submit method that would copy the form control values back to the Chapter object (I also coded the submit button to be disabled whenever the FormGroup representing the form was flagged as invalid):

    
      submitForm() {
        this.checkFormValidity()
        if( this.form.valid ) {
          this.chapter.name = this.form.value.name; //value is a key/value map
          this.chapter.guildId = +this.form.value.guild; //need this translated to number, hence +
          this.chapter.headChapter = this.form.value.headChapter === "true";
          this.chapter.defenses = [];
          for( let db in this.defenseBoxArray.controls ) {
            if( this.defenseBoxArray.controls[ db ].value == true ) {
              this.chapter.defenses.push( this.defenseArray[ db ].id )
            }
          }
        }
      }
    

    I then added interpolations to the template that would display the state and raw error values of the form controls as well as the current Chapter model values so I could watch everything in action when using the form:

    Some final notes:

    • You may notice in the animated GIF of the form that the reset action did not clear the radio buttons. That's due to the fact that I'm still using RC5: that bug was fixed in the official release of Angular 2.

    • Although you can supply a validator function as an argument when instantiating a new FormGroup, for some reason the FormBuilder syntax for creating a FormGroup does not allow you to provide a validator. So if you need to add validation to a FormGroup object, instantiate the object ahead of time and then reference it in the FormBuilder construction (just like I did with my FormArray).

    Saturday, September 24, 2016

    Learning Angular 2: Populating Properties With the Constructor And Using Promise.all

    Version 0.0.5 of my GuildRunner sandbox Angular 2 application was focused on updating the model object graph of the application (mainly to provide more opportunities for exploring forms), which included the following changes:

    • Removed the Address domain class and replaced it with a Location object containing traditional, basic address properties. 
    • Created a Person class containing properties such as first name and last name as well as a "residence" property that is an instance of Location.
    • Added the concept of "Chapter", where each Guild has a number of geographically-based Chapters.  Each Chapter domain class is associated with a Guild and has a "location" property that is an instance of ChapterLocation, another new domain class that extends Location and contains properties like "floors" and "entryPoints".
    • Removed the Member domain class and replaced it with ChapterMember, which extends the Person class.
    • Simplified the Guild domain class.
    • Created new master list view for the Chapters and ChapterMembers and added them to the navigation bar.
    During the process of refactoring the domain classes, I refined my approach to setting the domain class properties via the constructor.  Previously, I simply declared my properties (with a data type where appropriate) and used ternary operations to set the individual property values like so:
    
    // domain/guild.ts
    export class Guild {
      id: number;
      name: string;
      email: string;
      incorporationYear: number;
    
      constructor( guildData?: any  ) {
        if( guildData ) {
          this.id = guildData.id ? guildData.id : null ;
          this.name = guildData.name ? guildData.name : null ;
          this.email = guildData.email ? guildData.email : null;
          this.incorporationYear = guildData.incorporationYear ? guildData.incorporationYear : null;
        }
      }
    

    It worked, but it would get tedious and hard to read with larger property sets. And having default values set by conditional logic isn't very "default-like" behavior. Compare that to the constructor method I wrote for the new Chapter domain class:

    
    // domain/chapter.ts
    import { ChapterLocation } from './chapter-location';
    
    export class Chapter {
      id: number = null;
      guildId: number = null;
      name: string = null;
      location: ChapterLocation = new ChapterLocation();
      headChapter: boolean = false;
      founded: Date = null;
      defenses: Number[] = [];
    
      constructor( chapterData?: any ) {
        if( chapterData ) {
          let props = Object.keys( this );
          for( let p in props ) {
            if( chapterData[ props[p] ] ) {
              if( props[p] == 'location' ) {
                this.location = new ChapterLocation( chapterData.location )
              } else {
                this[ props[p] ] = chapterData[ props[p] ];
              }
            }
          }
        }
      }
    
    }
    

    It's worth noting that the technique of looping through the properties via Object.keys() only works if we have default values set for each property: properties without values are considered undefined and aren't retrieved by Object.keys().

    I also realized that my new master lists of guild chapters and chapter members would look more realistic if they included related data, so I could for example denote the guild and chapter each member belonged to.

    Under real-world conditions, a REST request for chapter members would probably include the related guild and chapter data in the returned data. But simulating that kind of all-inclusive data set with the in-memory web API is a bit problematic, because any changes I made to the Guild or Chapter data via the API wouldn't be reflected in the ChapterMember data set. So to avoid that problem, I needed to retrieve the full list of guilds and chapters along with the full list of members.

    In Angular 1x, when you needed to collect data returned by multiple promises before proceeding, you could use $q.all() to combine all of the promise results into an array that would become available only after all of the promises returned successfully.  I was able to do the same thing with Promise.all():

    
    // members-master/members-master-component.ts
    export class MembersMasterComponent implements OnInit {
    
      members: ChapterMember[] = [];
      chapters: any = {};
      guilds: any = {};
    
      constructor(
        private memberService: MemberService,
        private chapterService: ChapterService,
        private guildService: GuildService
      ) { }
    
      ngOnInit() {
    
        Promise.all( [ //the array of service calls that return Promises
          this.memberService.getMembers(),
          this.chapterService.getChapters(),
          this.guildService.getGuilds()
        ]).then( (results:Promise[]) => {
          results[0]['data'].forEach( memberData => {
            this.members.push( new ChapterMember( memberData ) )
          });
          results[1]['data'].forEach( chapterData => {
            this.chapters[ chapterData.id ] = chapterData
          });
          results[2]['data'].forEach( guildData => {
            this.guilds[ guildData.id ] = guildData
          });
        });
    
      }
    
    }
    

    Each service method call returns an instance of my HttpResponse class where the "data" property is populated with the array of member, chapter, and guild data returned by the in-memory web API, and the code loops over each array. Note that the code doesn't access the "data" property via dot-notation: when I tried using dot-notation ("results[0].data") I got a compiler error stating that "data" was not a property of the object. Not sure why: I probably have it coded in such a fashion that TypeScript doesn't recognize the results item as an HttpResponse despite the data typing.

    Note that only the member data gets translated into instantiated domain class objects (ChapterMember objects): for the chapters and the guilds, I simply need to capture them such that they can be referenced in the component view:

    
    <-- members-master/members-master.component.html -->
    <h3>Chapter Members</h3>
        <table class="table table-bordered table-striped">
          <thead>
          <tr>
            <th>ID</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Guild</th>
            <th>Chapter</th>
            <th>Active?</th>
          </tr>
          </thead>
          <tbody>
          <tr *ngFor="let member of members">
            <td>{{member.id}}</td>
            <td>{{member.firstName}}</td>
            <td>{{member.lastName}}</td>
            <td>{{guilds[chapters[member.chapterId].guildId].name}}</td>
            <td>{{chapters[member.chapterId].name}}</td>
            <td>{{member.isActive ? 'Yes' : 'No'}}</td>
          </tr>
          </tbody>
        </table>
    

    Again, this is not the ideal way of gathering related data for a master display of records, but in this case it gets the job done.