What types of directives exist in Angular?
Angular has three types of directives:
- Components - a special kind of directive with a template (
template). Essentially, a component is a directive with a UI. - Attribute directives - change the appearance or behavior of existing elements without changing the DOM structure.
Examples:
ngClass,ngStyle, custom directives likeappHighlight. - Structural directives - change the DOM structure by adding, removing or repeating elements.
Examples:
*ngIf,*ngFor,*ngSwitch.
Conclusion: components control the UI, attribute directives change element properties, and structural directives change the DOM's composition.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.