I would like to set different methods to be called at the (click) event. I created an array of dictionaries in the ts-File:
headerElements = [
{
descriptor: "Name",
icon: "/assets/imgs/name-32.png",
cursor: "default",
event: "null"
},
{
descriptor: "Price",
icon: "/assets/imgs/description-32.png",
cursor: "pointer",
event: "orderByPrice()"
},
{
descriptor: "Link",
icon: "/assets/imgs/timer-32.png",
cursor: "default",
event: "null"
},
{
descriptor: "Datum",
icon: "/assets/imgs/timer-32.png",
cursor: "pointer",
event: "null"
}
];
The orderByPrice-Method looks like this:
orderByPrice() {
this.isSortedAsc = !this.isSortedAsc;
const direction = this.isSortedAsc ? "desc" : "asc";
this.gearPieces = this.gearService.getGearComponentsOrderByPrice(direction);
}
I call it like this in the html-File:
<table class="table table-dark">
<thead>
<tr>
<th *ngFor="let header of headerElements">
<img src={{header.icon}} width="32" height="32" style="cursor: {{header.cursor}};" (click)="{{header.event}}"/>{{header.descriptor}}
</th>
</tr>
</thead>
</table>
Unfortunately, setting a specific method to be called on (click) gives me this error:
Template parse errors: Parser Error: Got interpolation ({{}}) where expression was expected at column 0 in [{{header.event}}]
Is it even possible, to accomplish this?