我刚刚在登录表单中添加了ngxErrors
:
<form (ngSubmit)="login()" [formGroup]="loginForm">
<ion-row>
<ion-col>
<ion-list inset>
<ion-item>
<ion-input type="text" placeholder="Email" formControlName="email"></ion-input>
</ion-item>
<div ngxErrors="email">
<div ngxError="['email', 'required']" when="touched">Email is required</div>
</div>
<ion-item>
<ion-input type="password" placeholder="Password" formControlName="password"></ion-input>
</ion-item>
<div ngxErrors="password">
<div ngxError="['minlength', 'required']" when="dirty">Password should be at least 5 characters</div>
</div>
</ion-list>
</ion-col>
</ion-row>
</form>
在login.ts
文件中,我有:
this.loginForm = fb.group({
email: ['', Validators.compose([Validators.required, Validators.email])],
password: ['', Validators.compose([Validators.required, Validators.minLength(6)])]
});
问题在于错误消息始终显示在输入字段下,我不希望仅在touched
或dirty
上显示错误消息。