Skip to main content

What is a structural directive?

A structural directive in Angular is a directive that changes the DOM structure by adding, removing or repeating elements.

Details:

  1. Usually applied with an asterisk (*) in the template, for example *ngIf or *ngFor.
  2. Controls the presence or number of elements in the DOM, not just their styles or behavior.
  3. Used for conditional rendering, loops or template switching.

Examples:

html
<p *ngIf="isVisible">This text is shown only if isVisible = true</p> <ul> <li *ngFor="let item of items">{{ item }}</li> </ul>

Conclusion: structural directives control the HTML structure itself, deciding which elements should be added to or removed from the DOM.

Short Answer

Interview ready
Premium

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