This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 class used before it was declared
- Loading branch information
1 parent
0522afa
commit 66d27a6
Showing
6 changed files
with
52 additions
and
43 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
projects/ngx-errors/src/lib/error-state-matchers.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Inject, Injectable, Optional } from '@angular/core'; | ||
import { | ||
ErrorStateMatcher, | ||
ShowOnDirtyErrorStateMatcher, | ||
} from '@angular/material/core'; | ||
import { | ||
CustomErrorStateMatchers, | ||
CUSTOM_ERROR_STATE_MATCHERS, | ||
} from './custom-error-state-matchers'; | ||
import { | ||
ShowOnSubmittedErrorStateMatcher, | ||
ShowOnTouchedAndDirtyErrorStateMatcher, | ||
ShowOnTouchedErrorStateMatcher, | ||
} from './error-state-matchers'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ErrorStateMatchers { | ||
private matchers: { [key: string]: ErrorStateMatcher } = {}; | ||
|
||
constructor( | ||
showOnTouchedErrorStateMatcher: ShowOnTouchedErrorStateMatcher, | ||
showOnDirtyErrorStateMatcher: ShowOnDirtyErrorStateMatcher, | ||
showOnTouchedAndDirtyErrorStateMatcher: ShowOnTouchedAndDirtyErrorStateMatcher, | ||
showOnSubmittedErrorStateMatcher: ShowOnSubmittedErrorStateMatcher, | ||
@Optional() | ||
@Inject(CUSTOM_ERROR_STATE_MATCHERS) | ||
customErrorStateMatchers: CustomErrorStateMatchers | ||
) { | ||
this.matchers['touched'] = showOnTouchedErrorStateMatcher; | ||
this.matchers['dirty'] = showOnDirtyErrorStateMatcher; | ||
this.matchers['touchedAndDirty'] = showOnTouchedAndDirtyErrorStateMatcher; | ||
this.matchers['formIsSubmitted'] = showOnSubmittedErrorStateMatcher; | ||
if (customErrorStateMatchers) { | ||
this.matchers = { ...this.matchers, ...customErrorStateMatchers }; | ||
} | ||
} | ||
|
||
get(showWhen: string): ErrorStateMatcher | undefined { | ||
return this.matchers[showWhen]; | ||
} | ||
|
||
validKeys(): string[] { | ||
return Object.keys(this.matchers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters