I have a custom control that implements both MatFormFieldControl and ControlValueAccessor, and although the form is invalid and has error I cannot get mat-error to display.
Main formgroup:
<form [formGroup]="formGroup">
<mat-form-field>
<app-test-input formControlName="testControl"></app-test-input>
<mat-hint>test</mat-hint>
<mat-error *ngIf="formGroup.get('testControl').hasError('required')">
required
</mat-error>
</mat-form-field>
<button (click)="submit()">Submit</button>
</form>
<p *ngIf="formGroup">
{{formGroup.value | json}} {{
formGroup.get('testControl').hasError('required') }}
</p>
custom control:
<div [formGroup]="FormGrp">
<input formControlName="data" (input)="input()" />
</div>
Here is a stackblitz https://stackblitz.com/edit/angular-tzgaxz-upn2yn
I would expect clicking the submit button to show the error, but I cannot figure out where I am going wrong. The error only appears when blurring the input.