import {Component, EventEmitter, Input, Output} from '@angular/core';
import {QuestionInterface} from './types/question.interface';
import {FormGroup, ValidationErrors} from '@angular/forms';
@Component({
selector: 'dyn-question',
template: `
Help
{{question.description}}
`
})
export class DynQuestionComponent {
@Input() question: QuestionInterface;
@Input() type: "'insert'|'update'|'delete'|'view'";
@Input() form: FormGroup;
@Output() onChange: EventEmitter = new EventEmitter();
public hoverState: any = false;
private errorList: Array = [];
onHover(state: boolean) {
this.hoverState = state;
}
change() {
setTimeout(() => {
this.errorList = [];
let control = this.form.controls[this.question.properties.key];
if (control.untouched || control.valid)
return null;
let errors: ValidationErrors = control.errors;
for (let key in errors) {
if (errors.hasOwnProperty(key)) {
this.errorList.push(errors[key].message);
}
}
this.onChange.emit();
}, 0);
}
}