ng-template
ng-template
The <ng-template>
is an Angular element for rendering HTML. It is never displayed directly. In fact, before rendering the view, Angular replaces the <ng-template>
and its contents with a comment.
If there is no structural directive and you merely wrap some elements in a <ng-template>
, those elements disappear.
Source
<p>Hip!</p>
<ng-template>
<p>Hip!</p>
</ng-template>
<p>Hooray!</p>
Result
Hip!
Hooray!
ng-template with *ngTemplateOutlet
Save template to a ref
and then output with *ngTemplateOutlet
directive.
Source
<ng-template #templateRef>Hello!</ng-template>
<div *ngTemplateOutlet="templateRef"></div>
Result