vendredi 31 juillet 2015

Active class on links angular js with ng-click?

I have a menu with links that are loaded from a json file. I am wondering what is the best way to add an active class when the user clicks the link. I have seen examples with unordered lists, but none with actual links. I have tried it with ng-click on the anchor tag, but it doesnt work. Here is the code that I have so far. What do you suggest is the best way to implement this?

Menu.html

<ul ng-controller="menuList">
   <li ng-repeat="words in allTerms track by $index"  ng-class="{ 'active': $index == selectedIndex}"><a href  id="{{ $index }}" ng-click="testing($event); PracticeTerm(); itemClicked($index);">{{words.term}}</a></li>
</ul>

controller.js

$scope.selectedIndex = 0;

$scope.itemClicked = function($index) {
    console.log($index);
    $scope.selectedIndex = $scope.allTerms[$scope.shared[$scope.shared.length - 1]].term;
};

Aucun commentaire:

Enregistrer un commentaire