您能告诉我为什么这不起作用吗? <mat-error *ngIf="email.errors.email">
。但这很好。 <mat-error *ngIf="email.errors.required"> Email is required.
<form name="form" (ngSubmit)="f.form.valid && submit()" #f="ngForm" novalidate>
<div class="form-group">
<mat-form-field>
<mat-label>Email</mat-label>
<input matInput type="email" name="email" placeholder="Email address" autocomplete="off" [(ngModel)]="model.email"
#email="ngModel" email="true" required>
<mat-error *ngIf="email.errors.email">
Email is invalid.
</mat-error>
<mat-error *ngIf="email.errors.required">
Email is required.
</mat-error>
</mat-form-field>
</div>
</form>
答案 0 :(得分:0)
找到了解决方案。应该是这样。
注意:?
是重要的部分。
<mat-error *ngIf="email.errors?.email && !email.errors?.required">
Email is invalid.
</mat-error>