我有一个文本框,上面有一个电子邮件模式,如果模式失败,我想用(点击)隐藏一个范围。以下是我认为应该工作的内容
<input type="text" placeholder="Signup for Mailing List" #userEmail="ngModel" style="width:300px" name="email" [(ngModel)]="email" pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" required email>
<span (click)="signup()" class="fa fa-envelope-o" *ngIf="userEmail.touched && !userEmail?.valid" style="position: relative;z-index: 1;cursor:pointer;left: -35px;width: 0; color:gray"></span>
这是* ngIf错了吗?该按钮从不显示
答案 0 :(得分:1)
<input type="text" placeholder="Signup for Mailing List"
#userEmail="ngModel" style="width:300px"
name="emails" [(ngModel)]="emails"
pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" required email>
<span (click)="signup()" class="fa fa-envelope-o"
*ngIf="userEmail.touched && userEmail?.valid" // remove the !sign
style="position: relative;z-index: 1;cursor:pointer;left: -35px;width: 0; color:gray"></span>
希望这就是你要找的东西。