I don't know what is your requirement to make it dynamic but... TemplateRef is not for that.
TemplateRef => it is block scoped though it has the same name while looping.
You can use the ViewChildren
decorator which returns all items of an ItemType
and the remaining magic Angular
does it for you.
component.ts
<div *ngFor="let i of [0, 1, 2, 3]" #items>
<button (click)="onClick(items, i)">Click on item {{ i }}</button>
</div>
.html
@ViewChildren('items') items: ItemType<ElementRef>;
onClick(item, i) {
console.log('item clicked : ', item);
console.log('index of item : ', i);
console.log('all items : ', this.items)
}
I'm not clear, what do you want but I just showed a way with click
event please apply it for your input
for more details please check: https://stackoverflow.com/a/44441164/5835354