NgFor object on click event

I am working on an application that shows a list of items (with ngFor) that also have an "add" button. When you click on the button, the element should be displayed in a separate list:

<ul>
    <li *ngFor="let trooper of impalasum">
        {{trooper.name}} <button id="btn_{{trooper.name}}" (click)="addToList({{trooper}})">Add</button>
    </li>
</ul> 
<hr>
<ul>
    <li>{{addedTrooper.name}} -> XY</li>
</ul>

      

addToList(troop: Trooper): void{
    this.addedTrooper = troop;
}

      

I want to have trooper as a parameter in the click event, but this way it doesn't work. So how can I do this?

+3


source to share


1 answer


Don't use interpolation in pin binding



(click)="addToList(trooper)"

      

+3


source







All Articles