I'm trying to put an error message in the template, but I'm not able to get into the validator I created.
This is the validator:
criarFormularioDeUsuario() {
this.formularioLogin = this.fb.group({
email: ['', Validators.compose([Validators.required, Validators.email])],
password: ['', Validators.compose([Validators.required])],
});
}
In the template I tried:
<mat-form-field class="full-width">
<input [errorStateMatcher]="matcher" formControlName="email" matInput placeholder="Email">
<mat-error *ngIf="formularioLogin.email.errors.email">
Você precisa entrar com um e-mail válido.
</mat-error>
</mat-form-field>
I also tried with hasError:
<mat-error *ngIf="formularioLogin.hasError('email') || formularioLogin.hasError('required')">
It did not work either.