Skip to content

Instantly share code, notes, and snippets.

@camilogiraldo
Last active February 28, 2019 01:40
Show Gist options
  • Save camilogiraldo/7f02de99809dba50a56352562a26c5bd to your computer and use it in GitHub Desktop.
Save camilogiraldo/7f02de99809dba50a56352562a26c5bd to your computer and use it in GitHub Desktop.
import { FormData } from './../../shared/interface/form-data';
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'app-dynamic-form',
templateUrl: './dynamic-form.component.html',
styleUrls: ['./dynamic-form.component.scss']
})
export class DynamicFormComponent implements OnInit {
@Input()formData: FormData[];
form: FormGroup;
constructor() {}
/** Setting up our form **/
ngOnInit() {
const formGroup = {};
this.formData.forEach(formControl => {
formGroup[formControl.controlName] = new FormControl('');
});
this.form = new FormGroup(formGroup);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment