recently working on a project, click the menu on the left to generate the corresponding table, as follows
form:
, now we have a problem, that is, we are adding a new form page, because the entire form page is dynamically generated and the verification cannot be completed (my current ability is limited). I see ide/dynamic-form" rel=" nofollow noreferrer "> ng6 official dynamic form instance . Although the form is also dynamic, all items in the form are instances of the same class, and
ts:
export class DynamicFormQuestionComponent {
@Input() question: QuestionBase<any>;
@Input() form: FormGroup;
get isValid() { return this.form.controls[this.question.key].valid; }
}
html:
<div >
<input [formControlName]="question.key" [id]="question.key" [type]="question.type">
</div>
<div class="errorMessage" *ngIf="!isValid">{{question.label}} is required</div>
, I would like to ask, in the ts file, 1. get isValid ()
function, 2. And why the get isValid ()
function polls all input controls when entering
data in the form form, and why this.question.key
can
switch properties in the QuestionBase
class when polling; 3. If the data in the form is now completely dynamic (that is, it is not an instance of QuestionBase
), how do you validate the data in the form?