What is the best way to conditionally apply a class?
Asked 07 September, 2021
Viewed 938 times
  • 53
Votes

Lets say you have an array that is rendered in a ul with an li for each element and a property on the controller called selectedIndex. What would be the best way to add a class to the li with the index selectedIndex in AngularJS?

I am currently duplicating (by hand) the li code and adding the class to one of the li tags and using ng-show and ng-hide to show only one li per index.

22 Answer