我花了很長(zhǎng)時(shí)間來理解一些應(yīng)該很容易的事情。表單驗(yàn)證。我第一次使用反應(yīng)形式。我正在使用表單生成器。我有一組嵌套的控件。一般來說,我假設(shè)您創(chuàng)建了一組帶有驗(yàn)證的控件,然后在模板中檢查這些控件。我能夠提交表單,但在嘗試創(chuàng)建驗(yàn)證消息時(shí)不斷收到錯(cuò)誤消息。------ TEMPLATE -------<div class="container"> <div class="row"> <div class="col-sm"> <!-- Begin card --> <div class="card border"> <div class="card-header bg-light text-primary"> <h3>My Account</h3> </div> <div class="card-body border border-light"> <!-- CHANGE PASSWORD BUTTON --> <div class="row"> <div class="col-sm"> <button class="btn btn-success" (click)="goToChangePassword()">Change Password</button> </div> </div> <!-- Begin Form --> <form *ngIf="user; else loading" [formGroup]="accountForm" (ngSubmit)="updateUser()"> <hr> <!-- Phone --> <fieldset formGroupName="phone"> <div class="form-row"> <div class="form-group col-sm"> <label>Home Phone</label> <input type="number" class="form-control" formControlName="home"> <div *ngIf="isSubmitted && fControls.home.errors" class="invalid-feedback"> <div *ngIf="fControls.home.errors.minlength">10 characters min</div> </div> </div> <div class="form-group col-sm"> <label>Mobile Phone</label> <input type="number" class="form-control" formControlName="mobile"> <div *ngIf="isSubmitted && fControls.mobile.errors" class="invalid-feedback"> <div *ngIf="fControls.mobile.errors.minlength">10 characters min</div> </div> </div>
Angular Reactive Forms - 驗(yàn)證錯(cuò)誤 - 無法讀取未定義或空值的屬性
ITMISS
2021-12-23 14:53:05