Skip to main content

What types of directives exist in Angular?

Angular has three types of directives:

  1. Components - a special kind of directive with a template (template). Essentially, a component is a directive with a UI.
  2. Attribute directives - change the appearance or behavior of existing elements without changing the DOM structure. Examples: ngClass, ngStyle, custom directives like appHighlight.
  3. 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 ready
Premium

A concise answer to help you respond confidently on this topic during an interview.