Open In App

Angular 10 NgTemplateOutlet Directive

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: 

Example 1:




<ng-container *ngTemplateOutlet="gfg"></ng-container>
  
<ng-template #gfg>
    <h1>GeeksforGeeks</h1>
  
    <div>
        ngTemplateOutlet Directive
    </div>
</ng-template>

Output:

Example 2:




<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


Article Tags :