i want to change the color of an element inside my angular app by using dynamic class,
here is my code , its works but not as expected, i have to reload the page before the color of my element change . there is my code .
i hope you can help me
thanks you in advance
<div class="w-full h-10 flex items-center px-4 cursor-pointer hover:bg-gray-200" [class]="file.id == id.id ? 'bg-blue-100' : '' " (click)="navigate(file.id)">
{{ file.id }}
</div>
2
Answers
you can inject ChangeDetectorRef and force angular to check for changes
in your function
You might want to look into the use of
ngClass
– e.g.Example is from here: https://blog.angular-university.io/angular-ngclass-ngstyle/