There are some possible solutions:
EXAMPLE 1:
A way using the "Angular way" would be to use the ng-class
and change it dynamically, like this:
<li ng-class='classeDinamica' id='li-1'>{{item.item}}</li>
and in the controller:
$scope.classeDinamica= 'nome-da-classe';
But this will alter all elements with classeDinamica
, and from what I’ve seen that’s not what you want.
EXAMPLE 2
For a particular element, you can use a selector, which is not much the "angular way", but it works:
angular.element(document.querySelector('#li-1')).addClass('nome-da-classe')
EXAMPLE 3
Another more elegant solution in the "angular way" is to use a logical expression with ng-class
using the element or the object itself Binding, in his case item:
<li ng-class="{'nome-da-classe': item.selecionado == true}" >{{item.item}}</li>
and in the controller, since you know which element (I used the index x):
$scope.itens[x].selecionado = true;
This will apply the class when the attribute selected the item is equal to true
.
EXAMPLE 4
Finally, if it is only one item selected in several, and as you said it has the $index
, you can create a value on $scope
to save the selected element, based on $index
and do as in the previous element of a ng-class
conditional, thus:
<li ng-class="{'nome-da-classe': $index == itemSelecionado}" >{{item.item}}</li>
and finally in controller:
$scope.itemSelecionado= $index;
Any of these solutions should help you