Nice ngClass tip
This is a useful thing I found while working on a Angular project, making a small note here in case I come across the need for something like this again.
I’m working on a project where I have to loop through a list of items and display them in a table. Pretty straight forward stuff. One requirement is that if a row contains an item with a certain name, then a Class needs to be added to this row so the front-end developer can style this row differently.
After doing some research into this I found out that using ngClass this is really easy to do.
Using ngRepeat I looped through the data creating the table, then on each row using ngClass you can check the matching value like this:
Ng-class=“{‘className’: value === ‘titleToMatch’}
What’s happening here is if the value matches the titleToMatch then the className is applied to the row.
Ng-class is really flexibile and it’s well worth looking into what you can do with it.