首页 > 解决方案 > 如何在一行中验证所有输入的属性?

问题描述

我想验证输入中的所有属性,但在这里不起作用

    <input id="cardCode" ngModel #cardCode="ngModel" name="cardCode" type="tel" required maxlength="3" required minlength="3" class="form-control cc-cvc" required autocomplete="off">

   <div  style="background-color:orange;font-weight: bold;"                               
    *ngIf="cardCode.touched && cardCode.errors?.required &&
  cardCode.errors?.required" >
   This is not valid CVC </div>

标签: angulartypescriptvalidation

解决方案


尝试这个:

<div  style="background-color:orange;font-weight: bold;"                              
 *ngIf="cardCode.touched && !cardCode.valid" >
 This is not valid CVC </div>

angular 基于验证器添加了一个无效的类。


推荐阅读