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:
- Grouping elements without an extra tag in the DOM.
- Using structural directives (
*ngIf,*ngFor) on a group of elements. - 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
isVisibleis false, nothing renders inside<ng-container>, and no extra<div>or other tag is added to the DOM.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.