angular / angular/components

bug(ErrorStateMatcher): Not able to configure globally ErrorStateMatcher

Open
#20,097 4 comments 2 reactions 0 assignees View on GitHub
area: material/input P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

#### Reproduction

StackBlitz link for reproduction: https://stackblitz.com/edit/components-issue-enshvf

Steps to reproduce:
1. Pay your attention that CoreModule has declaration for `ErrorStateMatcher` provider with class `ShowOnDirtyErrorStateMatcher`. CoreModule imported into AppModule in the same way as FeatureModule.
2. Try to focus/blur example "Favorite Food" input and note that `ShowOnDirtyErrorStateMatcher` was not applied.

In big enterprise applications we should have clean modular structure without any SharedModule or MaterialModule to be imported into each feature module.

MatInputModule has hardcoded `ErrorStateMatcher` provider and when we import that module into our feature modules – our global `ErrorStateMatcher` provider is overwritten.

I suppose this issue related with PR #18962, but I believe this issue describes another problem with `ErrorStateMatcher`

#### Expected Behavior

ErrorStateMatcher can be defined globally

#### Actual Behavior

ErrorStateMatcher overwrites with each MatInputModule import

#### Environment

- Angular: 9+
- CDK/Material: 9+

Contributor guide

Open the contributing guide

Research direction

Start with the linked StackBlitz reproduction and trace how ErrorStateMatcher is provided by CoreModule, FeatureModule, and MatInputModule. Verify the provider behavior when MatInputModule is imported in multiple feature modules; done means a globally configured ErrorStateMatcher remains effective and the reproduction’s Favorite Food input uses it.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.