Angular Master (283 Qs)•Part 10: Reactive Forms, Standalone Components, Signals & NgRx (256 - 283)
What are the state CSS classes provided by ngModel?
junior LevelMost AskedCode ExampleSignalsComponentsState Management
The ngModel directive updates the form control with special Angular CSS classes to reflect it's state. Let's find the list of classes in a tabular format,
| Form control state | If true | If false |
|---|---|---|
| Visited | ng-touched | ng-untouched |
| Value has changed | ng-dirty | ng-pristine |
| Value is valid | ng-valid | ng-invalid |
Practical Code Example
text
// ngModel State CSS Classes:
// ng-untouched / ng-touched (visited)
// ng-pristine / ng-dirty (value changed)
// ng-valid / ng-invalid (passes validation rules)
// ng-pending (waiting for async validator)