import { Input, OnInit } from '@angular/core'; import { FormGroup, FormArray } from '@angular/forms'; export abstract class GroupInputComponent implements OnInit { @Input() control: FormGroup | FormArray; @Input() meta; formGroup: FormGroup; childMetaArray: Array; controlNames: Array; exposeMetaInTemplate: string[] = []; ngOnInit() { // Move meta variables up a level, for direct access in templates this.exposeMetaInTemplate.map(p => this[p] = this.meta[p] !== undefined ? this.meta[p] : this[p]); // Get the FormGroup, and information about the controls inside it this.formGroup = this.control as FormGroup; this.childMetaArray = Object.values(this.meta.meta); // Metadata array of all controls in group this.controlNames = Object.keys(this.formGroup.controls); } }