Skip to content
Snippets Groups Projects
section.component.ts 983 B
Newer Older
  • Learn to ignore specific revisions
  • rhenck's avatar
    rhenck committed
    import {
    
      Component, Input, OnInit
    
    rhenck's avatar
    rhenck committed
    } from '@angular/core';
    
    import { FormBuilder, FormGroup } from '@angular/forms';
    
    import { UnitPageSection } from '../../../../common/unit';
    import { FormService } from '../../../../common/form.service';
    
    rhenck's avatar
    rhenck committed
    
    @Component({
      selector: 'app-section',
      template: `
    
        <app-element-overlay
            *ngFor="let element of section.elements"
            [elementModel]="element"
            [parentForm]="sectionForm">
        </app-element-overlay>
    
    rhenck's avatar
    rhenck committed
    })
    
    export class SectionComponent implements OnInit {
    
      @Input() parentForm!: FormGroup;
    
    rhenck's avatar
    rhenck committed
      @Input() section!: UnitPageSection;
    
      @Input() sectionForm!: FormGroup;
    
      constructor(private formService: FormService, private formBuilder: FormBuilder) {}
    
    
      ngOnInit(): void {
    
        this.sectionForm = new FormGroup({
          elements: this.formBuilder.array([])
        });
    
        this.formService.registerFormGroup({
          formGroup: this.sectionForm,
          parentForm: this.parentForm,
          parentArray: 'sections'
    
    rhenck's avatar
    rhenck committed
    }