Answer the question
In order to leave comments, you need to log in
What is the best way to bind events to array elements when outputting via ngFor in Angular 2+?
Now the binding is done like this
<div *ngFor="let item of array">
<div (click)="someFunc(item)">{{item.name}}</div>
</div>
<div *ngFor="let item of array" (click)="someFunc(item)">
<div>{{item.name}}</div>
</div>
Answer the question
In order to leave comments, you need to log in
So nothing prevents to hang up on the parent in
the same way . event.target will have a bottom element. (click)="onClick($event)"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question