group-input.component.ts 819 B

1234567891011121314151617181920212223242526272829
  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. // Get the FormGroup, and information about the controls inside it
  16. this.formGroup = this.control as FormGroup;
  17. this.childMetaArray = Object.values(this.meta.meta); // Metadata array of all controls in group
  18. this.controlNames = Object.keys(this.formGroup.controls);
  19. }
  20. }