角反应形式验证原始需要递归

时间:2020-03-30 08:00:57

标签: angular typescript validation

嗨,我对角度8中的形式陈述有疑问。从代码中可以看出,我有三个求索字段处于循环中。数组和字段部分 在需要验证时,原始数据被破坏并且验证无法正常工作

<form [formGroup]="altriCampiForm">
      <div *ngIf="getFormType(sezione?.campi) === 'altro'">
        <div *ngFor="let campo of sezione?.campi; let i = index;">
          <label class="uxc-a-text-input uxc-a-text-input--with-label uxc-a-text-input--color-gray"
            data-t-name="UXCInput">
            <span class="uxc-a-text-input__wrap">
              <span class="uxc-a-text-input__label">{{campo}} *</span>
              <input aria-required="false"  type="text" name="campo" value=""
                class="uxc-a-text-input__input uxc-js-a-text-input__input"
                aria-describedby="validation-feedback-input-error" formControlName="campo">
            </span>
          </label>
        <!--problem with pristine
        <div [hidden]="altriCampiForm.controls(campo).pristine" class="text-danger">
            <p *ngIf="altriCampiForm.controls['campo'].errors != null">
              Campi obbligatori
            </p>
          </div>-->
        </div>
      </div>
    </form>
  </div>

this is the controller 
export class FormSezioneComponent {
 altriCampiForm: FormGroup = this.newAltriCampiForm() // CF: Codice Fiscale

  private newAltriCampiForm (): FormGroup {
    return new FormGroup({
      campo: new FormControl('', Validators.compose([
        Validators.required
      ]))
    })
  }
}

0 个答案:

没有答案