group-input.component.ts 749 B

123456789101112131415161718192021222324252627
  1. import { Input, OnInit } from '@angular/core';
  2. import { FormGroup, FormArray } from '@angular/forms';
  3. export abstract class GroupInputComponent implements OnInit {
  4. @Input()
  5. control: FormGroup | FormArray;
  6. @Input()
  7. meta;
  8. formGroup: FormGroup;
  9. childMetaArray: Array<StringMap>;
  10. controlNames: Array<string>;
  11. exposeMetaInTemplate: string[] = [];
  12. ngOnInit() {
  13. // Move meta variables up a level, for direct access in templates
  14. this.exposeMetaInTemplate.map(p => this[p] = this.meta[p] !== undefined ? this.meta[p] : this[p]);
  15. this.formGroup = this.control as FormGroup;
  16. this.childMetaArray = Object.values(this.meta.meta); // Metadata array of all controls in group
  17. this.controlNames = Object.keys(this.formGroup.controls);
  18. }
  19. }