I have a little problem with dynamically naming components / native elements in Angular4. For example I have a directive which take native element as a argument by @Input()
. It look like that:
<div class="container">
<div #content class="some-content">
(...)
</div>
</div>
<button type="button" [someDirective]="content"> Use content! </button>
It works fine. But I would like to use a few contents in the same way, so I use a array of contents:
<div class="container" *ngFor="let elem of arrays; let index = index;">
<div #content class="some-content">
(...)
</div>
</div>
<button type="button" [someDirective]="content"> Use content! </button>
OFC, i will get error, because #content will not be unique. And this is my question: Is there a way to dynamically creating referece to element? I mean, something like:
<div class="container" *ngFor="let elem of arrays; let index = index;">
<div #content${index} class="some-content">
Anyone knows solution for this problem? I must add this is only a example. I meet this problem again, so I must know how resolve this kind of issue (so extract class="container" element to separate component is not answer for me.)