@@ -24,23 +24,25 @@ import { FormGroup } from '@angular/forms';
2424 </div>
2525 </div>
2626
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
3229 </div>
3330
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'])">
3736
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 }}
4143 </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 }}
4446 </div>
4547 </div>
4648
0 commit comments