我正在使用formGroup进行表单验证angular2.I正在对电话号码进行验证。我希望验证消息仅在用户离开字段/选项卡时才显示现在,验证工作正常,但验证信息即使在我专注于该领域时也会出现。 例如,如果我尝试更改电话号码并使数字等于10,它会引发错误(尽管我没有标签出来)。我只希望在显示时显示错误。任何想法,我在这里失踪。ANgular2-仅在用户离开字段时显示验证消息
<form [formGroup]="paymentDetailsForm">
<md-input formControlName="officePhone" placeholder="Primary Contact Phone" name="officePhone" [(ngModel)]="paymentform.officePhone" (blur)="registerChaseUser()" (keyup)="numberKeyed($event.target.value)" [restrictKey]="'^[0-9]+$'" noSpace="true" maxlength="14" required></md-input>
<span *ngIf="!paymentDetailsForm.controls['officePhone'].valid && (!paymentDetailsForm.controls['officePhone'].pristine || paymentDetailsForm.controls['officePhone'].touched || showPaymentError) && paymentform.officePhone.length == 0" class="validation validation-fix">This field is required.</span>
<span *ngIf="(paymentform.officePhone.length < 14) && (paymentform.officePhone.length > 0) && (!paymentDetailsForm.controls['officePhone'].pristine || paymentDetailsForm.controls['officePhone'].touched)" class="validation validation-fix">Please enter a full 10-digit phone number.</span>
</form>
如果您检查感动不应该工作? – LLL
它工作正常,但即使在我尝试更改数字时也会报错。 –