0 votes
1 view
in Web Technology by (21.3k points)
edited by

Let's say you have an array that is rendered in a ul with a li for each element and 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.

1 Answer

0 votes
by (52.8k points)

The best way to conditionally apply a class is as follows:-

ng-class="{selected: $index==selectedIndex}"

...