angular material mat-error on http request code example
Example: angular material mat-error on http request
control = new FormControl('', [Validators.required])
submit() {
this.control.setErrors({error_key: true})
}
<mat-form-field>
<mat-label>Control</mat-label>
<input type="text" formControlName="control" matInput />
<mat-error *ngIf="control.hasError('required')">
Control cannot be empty
</mat-error>
<mat-error *ngIf="control.hasError('error_key')">
My custom error message
</mat-error>
</mat-form-field>