Skip to content

bug(mat-form-field): mat-error is not displayed properly in nested @if #32398

@JoshThunar

Description

@JoshThunar

Description

When mat-form-field contains mat-error with a simple @if, then it is rendered properly. However, if we nest @if, error will be squished inside the form, instead of being present in mat-mdc-form-field-subscript-wrapper.

<mat-form-field appearance="outline">
  <input formControlName="bbb" matInput/>
      @if ( true ) {
        <mat-error>Nice error</mat-error>
      }
</mat-form-field>

Reproduction

https://stackblitz.com/edit/stackblitz-starters-nhxdncvv?file=src%2Fmain.ts

Expected Behavior

Renders properly:
Image

@if( true ) {
  <mat-error>Nice error</mat-error>
}

Actual Behavior

Doesn't render properly:
Image

@if( true ) {
  @if ( true ) {
    <mat-error>Terrible error</mat-error>
  }
}

Environment

  • Angular: 21
  • CDK/Material: 21

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue needs to be triaged by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions