问题:
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 . 假设你有一个在ul呈现的数组,每个元素都有一个li ,而控制器上的一个属性叫做selectedIndex 。 What would be the best way to add a class to the li with the index selectedIndex in AngularJS? 什么是一类添加到最好的办法li与指数selectedIndex在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. 我目前正在复制(手动) li代码并将类添加到其中一个li标签中,并使用ng-show和ng-hide仅显示每个索引一个li 。
解决方案:
参考一: https://stackoom.com/question/WhDw/有条件地申请课程的最佳方式是什么参考二: https://oldbug.net/q/WhDw/What-is-the-best-way-to-conditionally-apply-a-class
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4493017