ngxErrors-显示的错误消息即使不脏也不被触摸

时间:2018-07-05 13:32:35

标签: angular forms error-handling

我刚刚在登录表单中添加了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)])]
});

问题在于错误消息始终显示在输入字段下,我不希望仅在toucheddirty上显示错误消息。

0 个答案:

没有答案