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: 🐛 providing errorsModule in the lazy app module
- Loading branch information
1 parent
87d624a
commit b2f1488
Showing
16 changed files
with
104 additions
and
101 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,13 @@ | ||
import { Injectable, NgModule } from '@angular/core'; | ||
import { | ||
AbstractControl, | ||
FormGroupDirective, | ||
FormsModule, | ||
NgForm, | ||
} from '@angular/forms'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { | ||
CUSTOM_ERROR_STATE_MATCHERS, | ||
ErrorStateMatcher, | ||
NgxErrorsModule, | ||
} from '@ngspot/ngx-errors'; | ||
import { AppRoutingModule } from './app-routing.module'; | ||
import { AppComponent } from './app.component'; | ||
import { HomeComponent } from './home/home.component'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ShowOnDimaErrorStateMatcher implements ErrorStateMatcher { | ||
isErrorState( | ||
control: AbstractControl | null, | ||
_form: FormGroupDirective | NgForm | null | ||
): boolean { | ||
return !!(control && control.value === 'dima'); | ||
} | ||
} | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ShowOnFiveErrorStateMatcher implements ErrorStateMatcher { | ||
isErrorState( | ||
control: AbstractControl | null, | ||
_form: FormGroupDirective | NgForm | null | ||
): boolean { | ||
return !!(control && control.value && control.value.length === 5); | ||
} | ||
} | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserModule, | ||
AppRoutingModule, | ||
BrowserAnimationsModule, | ||
FormsModule, | ||
MatInputModule, | ||
NgxErrorsModule.configure({ | ||
showErrorsWhenInput: 'dima', | ||
}), | ||
], | ||
imports: [BrowserModule, AppRoutingModule, BrowserAnimationsModule], | ||
declarations: [AppComponent, HomeComponent], | ||
providers: [ | ||
{ | ||
provide: CUSTOM_ERROR_STATE_MATCHERS, | ||
useFactory: ( | ||
showOnDirtyErrorStateMatcher: ShowOnDimaErrorStateMatcher, | ||
showOnFiveErrorStateMatcher: ShowOnFiveErrorStateMatcher | ||
) => { | ||
return { | ||
dima: showOnDirtyErrorStateMatcher, | ||
five: showOnFiveErrorStateMatcher, | ||
}; | ||
}, | ||
deps: [ShowOnDimaErrorStateMatcher, ShowOnFiveErrorStateMatcher], | ||
}, | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} |
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,2 @@ | ||
export * from './show-on-dima-error-state-matcher'; | ||
export * from './show-on-five-error-state-matcher'; |
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,18 @@ | ||
import { Provider } from '@angular/core'; | ||
import { CUSTOM_ERROR_STATE_MATCHERS } from '@ngspot/ngx-errors'; | ||
import { ShowOnDimaErrorStateMatcher } from './show-on-dima-error-state-matcher'; | ||
import { ShowOnFiveErrorStateMatcher } from './show-on-five-error-state-matcher'; | ||
|
||
export const CUSTOM_ERROR_STATE_MATCHERS_PROVIDER: Provider = { | ||
provide: CUSTOM_ERROR_STATE_MATCHERS, | ||
useFactory: ( | ||
showOnDirtyErrorStateMatcher: ShowOnDimaErrorStateMatcher, | ||
showOnFiveErrorStateMatcher: ShowOnFiveErrorStateMatcher | ||
) => { | ||
return { | ||
dima: showOnDirtyErrorStateMatcher, | ||
five: showOnFiveErrorStateMatcher, | ||
}; | ||
}, | ||
deps: [ShowOnDimaErrorStateMatcher, ShowOnFiveErrorStateMatcher], | ||
}; |
13 changes: 13 additions & 0 deletions
13
projects/playground/src/app/custom-matchers/show-on-dima-error-state-matcher.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,13 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AbstractControl, FormGroupDirective, NgForm } from '@angular/forms'; | ||
import { ErrorStateMatcher } from '@ngspot/ngx-errors'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ShowOnDimaErrorStateMatcher implements ErrorStateMatcher { | ||
isErrorState( | ||
control: AbstractControl | null, | ||
_form: FormGroupDirective | NgForm | null | ||
): boolean { | ||
return !!(control && control.value === 'dima'); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
projects/playground/src/app/custom-matchers/show-on-five-error-state-matcher.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,13 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AbstractControl, FormGroupDirective, NgForm } from '@angular/forms'; | ||
import { ErrorStateMatcher } from '@ngspot/ngx-errors'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ShowOnFiveErrorStateMatcher implements ErrorStateMatcher { | ||
isErrorState( | ||
control: AbstractControl | null, | ||
_form: FormGroupDirective | NgForm | null | ||
): boolean { | ||
return !!(control && control.value && control.value.length === 5); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,26 +1 @@ | ||
<p>home works!</p> | ||
|
||
<mat-form-field appearance="fill"> | ||
<mat-label>Name</mat-label> | ||
|
||
<input | ||
matInput | ||
[(ngModel)]="name" | ||
required | ||
[minlength]="10" | ||
#nameModel="ngModel" | ||
autocomplete="off" | ||
/> | ||
|
||
<mat-error [ngxErrors]="nameModel.control"> | ||
<span ngxError="required"> Name is required </span> | ||
|
||
<span ngxError="minlength" showWhen="five"> | ||
Name should be at least 10 chars - FIVE | ||
</span> | ||
|
||
<span ngxError="minlength">Name should be at least 10 chars - DIMA</span> | ||
</mat-error> | ||
</mat-form-field> | ||
|
||
<pre>{{ nameModel.control.errors | json }}</pre> |
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