I'm trying to use ngClass to add a class on any span elements after the fourth one is added to the DOM (happens via a button click that increments a counter variable and also toggles the visibility of a paragraph), but I don't know how to make this to where any of the first four spans do not also get this class added once the fifth one is reached. I feel like this is easy to accomplish, but I'm stuck.
I tried adding an index to the *ngFor and then adding the class based on the index but that produced the same result.
Template:
<p *ngFor="let click of buttonClicks;">
<span [ngClass]="{ 'white': counter > 4 }">{{ [click] }}</span>
</p>
<button (click)="displayDetails()">Display Details</button>
<p *ngIf="detailsVisible">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Doloribus quasi id, molestiae doloremque alias non adipisci placeat corrupti commodi minus voluptas debitis eaque iure obcaecati minima neque et molestias atque.</p>
Component:
export class AppComponent {
detailsVisible: boolean = false;
buttonClicks: Array<number> = [];
counter: number = 0;
displayDetails() {
this.detailsVisible = !this.detailsVisible;
this.buttonClicks.push(this.counter);
this.counter++;
}
}