@@ -22,8 +22,9 @@ if the key is not present in the language file the message fallbacks to `${defau
2222
2323## Usage
2424
25+
2526Import it using
26- ```
27+ ``` typescript
2728import {NgxValidationErrorsModule } from ' @xtream/ngx-validation-errors' ;
2829
2930@NgModule ({
@@ -37,25 +38,52 @@ import {NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
3738export class AppModule {
3839}
3940```
41+ ### Components with auto errors injection
42+ now you can use validationContext and ngxValidationErrorsField in your template
4043
41- now you can use validationContext and formFieldContainer in your template
42-
43- ```
44+ ``` angular2html
4445<form [formGroup]="heroForm" validationContext="USER.REGISTRATION">
45- <div formFieldContainer >
46+ <div ngxValidationErrorsField >
4647 <label>Name</label>
4748 <input formControlName="name"/>
4849 </div>
4950</form>
5051```
52+ or
53+ ``` angular2html
54+ <form [formGroup]="heroForm" validationContext="USER.REGISTRATION">
55+ <ngx-validation-errors-field>
56+ <label>Name</label>
57+ <input formControlName="name"/>
58+ </ngx-validation-errors-field>
59+ </form>
60+ ```
5161
5262According to the Validators set in the FormControl the errors appear when the input is invalid, dirty and touched.
5363
64+ ### Structural directive
65+
66+ The structural directive has been created for special layout library (like material-ui) that have special input/errors
67+ components that do non allow to autoInject errors component. The usage is a little bit more verbose but the you control
68+ errors
69+
70+ ``` angular2html
71+ <form [formGroup]="heroForm" validationContext="USER.REGISTRATION">
72+ <mat-form-field *ngxValidationErrors="heroForm.get('name'); errors as errors">
73+ <input matInput formControlName="name" placeholder="name"/>
74+ <mat-error *ngIf="errors">{{errors}}</mat-error>
75+ </mat-form-field>
76+ </form>
77+ ```
78+
79+ the structural directive needs the form control as parameter (like heroForm.get('name'), if you find a better way to retrieve the inner form control instance please open an issue).
80+ It exposes errors in the template context so you can use them in the ui.
81+
5482### Clearing
5583
5684The ValidationContextComponent has an imperative clear that resets all the fields removing all the errors.
5785
58- ```
86+ ``` typescript
5987import {ValidationContextComponent } from ' @xtream/ngx-validation-errors' ;
6088
6189
@@ -71,7 +99,7 @@ import {ValidationContextComponent} from '@xtream/ngx-validation-errors';
7199
72100The library can be configured using the ` forRoot ` static method
73101
74- ```
102+ ``` typescript
75103import {NgxValidationErrorsModule } from ' @xtream/ngx-validation-errors' ;
76104
77105@NgModule ({
0 commit comments