Angular Material ErrorStateMatcher在提交父表单时是否可以检测到?

Angular Material ErrorStateMatcher在提交父表单时是否可以检测到?,angular,angular-material,angular-forms,Angular,Angular Material,Angular Forms,我有一个父组件,用于设置表单并将其传递给子组件 您不需要实现ErrorStateMatcher来实现这种行为。在mat表单字段上使用formGroup是没有意义的 只需更改child.component.html,如下所示 <mat-form-field *ngIf="form"> <input matInput placeholder="Email" [formControl]="form.get('email')"> </mat-form-field>

我有一个父组件,用于设置表单并将其传递给子组件



您不需要实现
ErrorStateMatcher
来实现这种行为。在
mat表单字段上使用
formGroup
是没有意义的

只需更改
child.component.html
,如下所示

<mat-form-field *ngIf="form">
  <input matInput placeholder="Email" [formControl]="form.get('email')">
</mat-form-field>


这是一个工作示例

对于任何试图实现此功能的人,请确保将
formControlName
更改为
[formControl]
(并使用
form.get
获得实际控制)。我还注意到在我的真实应用程序中使用
ChangeDetectionStrategy.OnPush
时出现的一个问题,虽然我无法在StackBlitz中重现这一点,但在遵循Angular关于DynamicForms()的文档并将其修改为使用Material之后,我遇到了完全相同的问题。@ysf的答案对我很有用。