Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k 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 (106k points)

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

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

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...