I am creating a form with Angular Material 2. I am using template driven form and I have email input which has two validators (required and email). In the doc for the input component (https://material.angular.io/components/component/input) it only says:
"If an input element can have more than one error state, it is up to the consumer to toggle which messages should be displayed. This can be done with CSS, ngIf or ngSwitch."
there is no example and I can't find it anywhere.
This is my html:
...
<form (ngSubmit)="onSubmit(registrationForm)" #registrationForm="ngForm">
...
<md-input-container floatPlaceholder="never">
<input mdInput type="email" placeholder="Enter your email address" name="email" [(ngModel)]="email" required email>
<md-error class="required">Email is required.</md-error>
<md-error class="email">Invalid email.</md-error>
</md-input-container>
...
Currently both messages are shown all the time. Even if I enter some invalid email.
Any of the mentioned solutions (CSS, ngIf or ngSwitch) would be fine but I'd prefer CSS.