Last active
February 28, 2019 01:40
-
-
Save camilogiraldo/7f02de99809dba50a56352562a26c5bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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