samedi 19 novembre 2016

multiple if checks in ng-class

So I have this piece of code in my angularjs app that I include in a table. I want to activate the class 'rare' if the index is 0, 1 or 2 only. The index is the rows. Let's say I have 8 rows in my table. Only the first 3 in it should have the class 'rare' applied to it.

ng-class="{rare : $index === 0, rare : $index === 1, rare : $index === 2}"

But is there an easier/shorter way of writing it? Is this good practice? I dont think it looks very good, even though it works. How would you write the if checks?

Aucun commentaire:

Enregistrer un commentaire