Angular 6 dynamic generation form validation problem

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:

is used.
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?

Jul.06,2021

The function of the

1.get isValid () function,
determines whether the form is reasonable before it is submitted, and returns a true if it is reasonable. So * ngIf= "! isValid" is unreasonable and will display a prompt.
for example, sometimes form is embedded in modal and there is no submit button, so you have to judge it in (nzOnOk) = "submitForm ()".

if(!this.isValid){
      return;
    }

2. [this.question.key] is not written dead, so you can find it dynamically.

3. Completely dynamic is traversing and inserting


const group = this.fb.group({});
this.config.forEach(control => group.addControl(control.name, this.fb.control('')));
Menu