I'm trying to change the class of certain elements based on a method's computation after 5 seconds:
<tr *ngFor="let row of items; let i = index">
...
<td #f [ngClass]="getColor(row, f)">Test 1</td>
<td #f2 [ngClass]="getColor(row, f2)">Test 2</td>
...
</tr>
Inside the component
getColor(row: any, f: any): string {
//I need to add a class based on some calculation
this.setClass(f)
return "aaa"; //set the aaa class
}
setClass(el: any) {
setTimeout(() => {
//remove the aaa class after 5 seconds
//this.renderer.removeClass(el.nativeElement, 'aaa');
}, 5000);
}
The problem is that el.nativeElement is "undefined", I think this is because the el type is HTMLElement instead of ElementRef.
Also I checked some similar question, like this https://stackoverflow.com/a/48700662/1395614 but in truth the problem remain.