Skip to main content

What does ng-container do?

<ng-container> in Angular is an invisible container in the template that does not create an extra DOM element, but lets you group elements or apply directives.

Main uses:

  1. Grouping elements without an extra tag in the DOM.
  2. Using structural directives (*ngIf, *ngFor) on a group of elements.
  3. Simplifying template logic without changing the HTML structure.

Example:

html
<ng-container *ngIf="isVisible"> <p>First element</p> <p>Second element</p> </ng-container>

Conclusion: if isVisible is false, nothing renders inside <ng-container>, and no extra <div> or other tag is added to the DOM.

Short Answer

Interview ready
Premium

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