Skip to content
Snippets Groups Projects
section.component.ts 1.01 KiB
Newer Older
  • Learn to ignore specific revisions
  • rhenck's avatar
    rhenck committed
    import {
    
      Component, Inject, Input, OnInit
    
    rhenck's avatar
    rhenck committed
    } from '@angular/core';
    
    import { FormBuilder, FormGroup } from '@angular/forms';
    
    import { DOCUMENT } from '@angular/common';
    
    import { FormService } from '../../services/form.service';
    
    rhenck's avatar
    rhenck committed
    import { Section } from '../../../../../common/models/section';
    
    rhenck's avatar
    rhenck committed
    
    @Component({
      selector: 'app-section',
    
      templateUrl: './section.component.html'
    
    rhenck's avatar
    rhenck committed
    })
    
    export class SectionComponent implements OnInit {
    
      @Input() parentForm!: FormGroup;
    
      @Input() section!: Section;
    
      @Input() parentArrayIndex!: number;
    
      sectionForm!: FormGroup;
    
      constructor(private formService: FormService,
    
                  private formBuilder: FormBuilder,
                  @Inject(DOCUMENT) public document: Document) {
    
    
      ngOnInit(): void {
    
        this.sectionForm = new FormGroup({
          elements: this.formBuilder.array([])
        });
    
        this.formService.registerFormGroup({
          formGroup: this.sectionForm,
          parentForm: this.parentForm,
    
          parentArray: 'sections',
          parentArrayIndex: this.parentArrayIndex
    
    rhenck's avatar
    rhenck committed
    }