Created
June 24, 2013 11:52
-
-
Save tcdevs/5849533 to your computer and use it in GitHub Desktop.
Angular get slectedIndex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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