How to include an ng-template element without a condition in Angular 2

  <ng-template #myTemplate>
      <h1>Some Header</h1>
      <p>Some text...</p>
  </ng-template>

  <ng-container *ngTemplateOutlet="myTemplate">
  </ng-container>

We can definitely use ‘ng-container’ to instantiate the ‘myTemplate‘ template on the page.

We are referring to the ‘myTemplate‘ template via its template reference #myTemplate, and we are using the ngTemplateOutlet structural directive to render the template.

ngTemplateOutlet directive inserts an embedded view from a prepared TemplateRef.

Leave a Comment

tech