import { Component, ViewEncapsulation, AfterViewInit, Input, OnInit, OnDestroy } from "@angular/core"; import { DataManagementPlanProfile } from "../../../models/data-management-plan-profile/DataManagementPlanProfile"; import { DMPProfileFieldDataType, DMPProfileType } from "../../../models/data-management-plan-profile/DataManagementProfileField"; import { FormGroup, FormBuilder, FormArray } from "@angular/forms"; import { LanguageResolverService } from "../../../services/language-resolver/language-resolver.service"; @Component({ selector: 'app-dynamic-dmp-field-resolver', templateUrl: 'dynamic-dmp-field-resolver.component.html', styleUrls: ['./dynamic-dmp-field-resolver.component.scss'], providers: [], encapsulation: ViewEncapsulation.None }) export class DynamicDmpFieldResolver implements OnInit, OnDestroy { DMPProfileFieldDataType = DMPProfileFieldDataType; DMPProfileType = DMPProfileType; @Input() dataManagementPlanProfile: DataManagementPlanProfile; @Input() formGroup: FormGroup ngOnInit(): void { this.formGroup.addControl("properties", new FormBuilder().group([])); (this.formGroup.get("properties")).addControl("fields", new FormBuilder().array([])) this.dataManagementPlanProfile.fields.forEach(item => { (this.formGroup.get("properties").get("fields")).push(new FormBuilder().group({ id: [item.id], value: [item.value] })) }) } ngOnDestroy(): void { this.formGroup.removeControl("properties") } }