Angular 如何在一行中验证所有输入的属性?

Angular 如何在一行中验证所有输入的属性?,angular,typescript,validation,Angular,Typescript,Validation,我想验证输入中的所有属性,但在这里不起作用 <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:or

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

    <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>

这是无效的CVC
试试这个:

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

这是无效的CVC

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

谢谢您的回答!在这个ngIf中添加模式怎么样?这是我的问题,实际上我也忘了添加是的,当我试图在错误发生后纠正时,你可以给出这样的模式,我想在你的解决方案中消除这个错误,直到语句变得正确为止。我只想看到错误,只有当它未被触及且无效,并且没有向ngIf structural指令添加模式时,你应该只给出一个返回booleanI的表达式,意思是没有模式。根据你的回答