@@ -24,23 +24,25 @@ import { FormGroup } from '@angular/forms';
24
24
</div>
25
25
</div>
26
26
27
- <div>
28
- Pristine: {{ store.hasError('required', ['pristine']) }}
29
- Dirty: {{ store.hasError('required', ['dirty']) }}
30
- Touched: {{ store.hasError('required', ['touched']) }}
31
- Touched, Dirty: {{ store.hasError('required', ['touched', 'dirty']) }}
27
+ <div *ngIf="myError.hasError('*', ['touched', 'dirty'])">
28
+ The control is invalid
32
29
</div>
33
30
34
- <div>
35
- <input [ngStyle]="{ borderColor: store.hasError('required', ['touched']) ? 'red' : 'grey' }" type="text" placeholder="Manager Code" formControlName="code">
36
- </div>
31
+ <input
32
+ type="text"
33
+ placeholder="Manager Code"
34
+ formControlName="code"
35
+ [class.required]="myError.hasError('required', ['dirty', 'touched'])">
37
36
38
- <div ngxErrors="store.code" #store="ngxErrors">
39
- <div class="error" ngxError="required" [when]="['touched']">
40
- Manager ID is required
37
+ <div ngxErrors="store.code" #myError="ngxErrors">
38
+ <div class="error" ngxError="required" [when]="['dirty', 'touched']">
39
+ Field is required
40
+ </div>
41
+ <div class="error" ngxError="minlength" [when]="['dirty', 'touched']">
42
+ Min-length is {{ myError.getError('minlength')?.requiredLength }}
41
43
</div>
42
- <div class="error" [ ngxError]="['minlength', ' maxlength'] " [when]="['dirty']">
43
- Minlength is 2, max length is 5
44
+ <div class="error" ngxError=" maxlength" [when]="['dirty', 'touched ']">
45
+ Max-length is {{ myError.getError('maxlength')?.requiredLength }}
44
46
</div>
45
47
</div>
46
48
0 commit comments