I have a list of items and when the user clicks on an item, this item gets highlited. We do this by simple adding *ngIf="object.shouldHeight" and works.
My Problem:
When the user clicks on another item, the previous selected item should be unhighlighted
My first idea for the solution:
The first solution I thought was to iterate through all items, change their status to false and then set the current status to true. This would work!
My second idea for the solution:
The other was to use this, but this is not working as toogle, means, when I click on a next item, the previous one is still highlighted.
How can I achieve this in Angular2 without writing loops in my code?
UPDATE:
I achieved this, althought I still think it could be more elegant:
In my component I have the following function:
public showButtonbar(i: number) {
this.hightlightStatus = []
this.hightlightStatus[i] = true;
}
And that is my click event, where i is the index:
(click)="showButtonbar(i)"