curious coder
curious coder

Reputation: 111

can I use ng template for a separate component and use its template reference in other html?

I am trying to use ng-template for a html which is a separate component ,and I am trying to use its reference in other html.. Is it possible? If so I have tried the below ways and would like to understand what is that I am going wrong with?

ng-template.html

<ng-template #sample1>  
  <p>ng template content</p>
</ng-template>

display-template.html

<div *ngIf="found;">
  <ng-container *ngTemplateOutlet="sample1"></ng-container>
</div>

DisplayTemplateComponent.ts

export class DisplayTemplateComponent   {
    @ViewChild('sample1', {static: false}) sample1: ElementRef;
    found = true;
}

Upvotes: 1

Views: 1451

Answers (1)

Fahd Lihidheb
Fahd Lihidheb

Reputation: 710

I think you should use a regular angular component instead of an ng-template if you want to use it globaly in your application.

I am not sure why you want to do it this way. Anyways this link may help you How to load the ng-template in separate file?.

Upvotes: 2

Related Questions