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
.
I'll add to this, because some of these answers seem out of date. Here's how I do it:
Where 'isSelected' is a javascript variable defined within the scoped angular controller.
To more specifically address your question, here's how you might generate a list with that:
HTML
-
{{item.name}}
JS
function ListCtrl($scope) {
$scope.list = [
{"name": "Item 1", "isSelected": "active"},
{"name": "Item 2", "isSelected": ""}
]
}
See: http://jsfiddle.net/tTfWM/
See: http://docs.angularjs.org/api/ng.directive:ngClass