In this article, we are going to see what is NgTemplateOutlet in Angular 10 and how to use it.
The NgTemplateOutlet in Angular10 is used to insert an embedded view from a prepared TemplateRef. NgTemplateOutlet adds the reference element which is displayed on the page.
Syntax:
<li *NgTemplateOutlet='condition'></li>
NgModule: Module used by NgTemplateOutlet is:
Selectors:
Approach:
- Create an angular app to be used.
- There is no need for any import for the NgIf to be used.
- in app.component.html add NgTemplateOutlet Directive to the element with its reference.
- Serve the angular app using ng serve to see the output.
Example 1:
app.component.html
< ng-container * ngTemplateOutlet = "gfg" ></ ng-container >
< ng-template #gfg>
< h1 >GeeksforGeeks</ h1 >
< div >
ngTemplateOutlet Directive
</ div >
</ ng-template >
|
Output:

Example 2:
app.component.html
< div * ngTemplateOutlet = "gfg" ></ div >
< ng-template #gfg>
< h1 >
GeeksforGeeks
</ h1 >
< div >
We can also use ngTemplateOutlet Directive with a div
</ div >
</ ng-template >
|
Output:

Reference: https://angular.io/api/common/NgTemplateOutlet