VOOZH about

URL: https://www.geeksforgeeks.org/angular-js/how-to-use-ngif-without-an-extra-element-in-angular2/

⇱ How to use ngIf without an extra element in Angular2? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to use ngIf without an extra element in Angular2?

Last Updated : 15 Jul, 2025
In order to use *ngIf without an extra element in Angular 2+, we can use either <ng-container> or <ng-template>
But in many cases, <ng-container> is recommended.
The best scenario regarding the usage of with *ngIf without an extra element is mentioned below.

app.component.ts:

app.component.html :

👁 Image
Illustration of above code for ng-container

If we inspect it then  we can see there is no extra element added after <div> tag and before <p> tag.

👁 Image
Comment
Article Tags:

Explore