I've tried to build an angular component to wrap a whole mat-form-field of Angular Material.
<mat-form-field>
<input matInput type="text" placeholder="{{ label }}" [(ngModel)]="_value"
[required]="required" [disabled]="_disabled"
(input)="intenrnalValueChange()" />
<mat-hint>{{ hint }}</mat-hint>
<mat-error>{{ getError() }}</mat-error>
</mat-form-field>
The component is working well, except by a little trouble. I cannot mark it as touched, and I believe is due to the component architecture. I've tried some solutions of StackOverflow (and others) that work well in the traditional way but does not work for my component.
this.form.get('field').markAsTouched(); // should work
this.form.markAsTouched(); // should not work
this.form.markAllAsTouched(); // should work
I want to mark the field touched by a button, which will show all the fields that are yet invalid (and their message by a mat-error).
I created a simplified project, where is possible to reproduce the problem. I want that when the button is clicked, the field becomes red and the message appears below. It does not happen, but if the field is clicked and blurred, the error is shown.
https://stackblitz.com/edit/angular-7mghym
The question is: how to change my project (keeping the component) in order to the button has the same effect to click and blur the field?