My HTML is creating dynamic divs with ngFor
<div class="container">
<div class="scroll" scrollX="true" >
<div *ngFor="let i of lotes" class="card" id="card_{{i.id_lote}}">
<div class="title">
{{ i.nome_lote }}
</div>
</div>
</div>
</div>
Then I'm looping an array with ID's and trying to set click listeners on those divs:
ngAfterViewInit() {
this.lotes.forEach(function(lote){
let card_instance = document.getElementById('card_'+id_lote);
console.log(card_instance); // <==================== this works and shows correct element
card_instance.addEventListener("click", (evt) => {
console.log('aaaahhhhh');
});
});
}
So I can reach the element but when I click it nothing happens. It looks like the addEventListener don't work...
Am I doing this the right way?