How to Validate & Display Error Message - Angular2 Material Design?
Hopefully this will be added as angular2-material evolves, but currently the way to mimic this is to set the dividerColor and use the MD-HINT directive. example:
<md-input placeholder="Email address"
#email="ngModel"
name="email"
type="text"
fullWidth={true}
[(ngModel)]="model.email"
required
email
dividerColor="{{ !email.valid ? 'warn' : 'primary' }}">
<md-hint [hidden]="email.pristine || email.valid">
<span [hidden]="email.errors?.required || !email.errors?.email">
This doesn't appear to be a valid email address.
</span>
<span [hidden]="!email.errors?.required">Email address is required.</span>
</md-hint>
</md-input>
Validation messages can now be inserted with Angular Material version 2.0.0 onward. Check the documentation here.
<form class="example-form">
<mat-form-field class="example-full-width">
<input matInput placeholder="Email" [formControl]="emailFormControl">
<mat-error *ngIf="emailFormControl.hasError('pattern')">
Please enter a valid email address
</mat-error>
<mat-error *ngIf="emailFormControl.hasError('required')">
Email is <strong>required</strong>
</mat-error>
</mat-form-field>
</form>