Skip to content

Instantly share code, notes, and snippets.

@tcdevs
Created June 24, 2013 11:52
Show Gist options
  • Save tcdevs/5849533 to your computer and use it in GitHub Desktop.
Save tcdevs/5849533 to your computer and use it in GitHub Desktop.
Angular get slectedIndex
<div ng-app="">
<div ng-controller="Ctrl">
<ul class="nav nav-list" ng-repeat="color in colors">
<li ng-click="setSelectedIndex(color)" ng-class="{active: selectedItem == color}">
<a href="#">{{color}} {{$index}}</a>
</li>
</ul>
<tt>selectedItem = {{selectedItem}}</tt>
</div>
</div>
<script>
function Ctrl($scope) {
$scope.colors = ['blue', 'green', 'red'];
$scope.selectedItem = undefined;
$scope.setSelectedIndex = function(item) {
$scope.selectedItem = item;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment