Learn CSS from the Best Tutors
Search in
Angular's `ngModel` directive doesn't directly add specific styling forms to CSS classes. However, Angular provides a set of classes that you can use to style form controls based on their validation state and user interaction. These classes are part of the Angular forms module.
Here are some of the common classes applied to form controls by Angular:
1. **ng-valid:** Applied to a form control when its value is valid according to the specified validation rules.
2. **ng-invalid:** Applied to a form control when its value is invalid according to the specified validation rules.
3. **ng-pristine:** Applied to a form control when it has not been touched by the user (pristine state).
4. **ng-dirty:** Applied to a form control when it has been touched by the user (dirty state).
5. **ng-touched:** Applied to a form control when it has been blurred or touched by the user.
6. **ng-untouched:** Applied to a form control when it has not been blurred or touched by the user.
These classes help you apply styles to form controls based on their state, making it easier to give users feedback on the validity of their inputs.
Example usage in CSS or Angular templates:
```css
/* Apply styles to invalid inputs */
input.ng-invalid {
border: 1px solid red;
}
/* Apply styles to valid inputs */
input.ng-valid {
border: 1px solid green;
}
/* Apply styles to touched (blurred) inputs */
input.ng-touched {
outline: none;
}
```
In Angular templates:
```html
<input type="text" [(ngModel)]="myValue" name="myInput" class="form-control" [ngClass]="{'is-invalid': myInput.invalid && (myInput.dirty || myInput.touched)}">
```
In this example, the `ng-invalid` class is applied when the input value is invalid, and the additional styling is applied conditionally using `[ngClass]` based on the control's `dirty` and `touched` states. Adjust the classes and styles based on your specific requirements.
Related Questions
Why is HTML is used in Web Application?
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Why Should you Learn HTML
Since the world today is ruled by the Internet, everyone desires to build a website for either business or personal interests. HTML or Hyper-text Mark-up Language is a globally standardized language which used to format web pages. By using HTML, the appearance of text, links, images and almost every part of a web page could...
Skills Required to Become a Front End Web...
Today, no business can exist without having its own website to interact with its customer base. Having a website is no more restricted to the big MNCs. With the advancement in technology and global business, even the small enterprises are spending on having their own websites and development teams. The person works on web...
Make a Career in Mobile Application Programming
Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...
Learn Microsoft Excel
Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...
Looking for CSS Training?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for CSS Classes are on UrbanPro
The best Tutors for CSS Classes are on UrbanPro