2

I have an *ngFor which iterates through users like:

<div *ngFor="let user of users>

</div>

I want to create ng templates like this:

<div *ngFor="let user of users>
   <ng-template #{{user.id}}> (is there a way to do that...?)
        --------call a component
   </ng-template>
</div>

and use them like this inside different components of my project

<div *ngFor="let user of users>
   <ng-container *ngTemplateOutlet="user.id">
   </ng-container>
</div>

So, my question is, can i declare tags dynamically to ng-template ?

Iraklis Bekiaris
  • 1,163
  • 15
  • 43
  • Is it for retrieving them with @ViewChildren ? Because I might have a workaround. – Julien Mar 09 '20 at 13:31
  • The idea is that i want to create "divs" on the background and call them in different components of my project so i wont have to load again and again. Because of the nature of the project, doing that with component or any other trivial solution will not work and its hard to explain why. So it is what it is as described in the question – Iraklis Bekiaris Mar 09 '20 at 13:35
  • So, will you end up calling your divs after retrieving them with `@ViewChildren` ? Or maybe JQuery or event pure javascript selectors? By the way this will not work because doesn't render any html in your dom. – Julien Mar 09 '20 at 14:49

0 Answers0