Created
October 17, 2013 05:22
-
-
Save HAKASHUN/7019497 to your computer and use it in GitHub Desktop.
AngularJSでng-classを使ってみた。
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
<html ng-app> | |
<head> | |
<meta charset="UTF-8"> | |
<title>restaurantTable</title> | |
<style> | |
.selected { | |
background: lightgreen; | |
} | |
</style> | |
</head> | |
<body> | |
<table ng-controller='RestaurantTableController'> | |
<!-- | |
ng-classの指定 | |
クリックした<tr>のindexとselextedRowが一致したら selectedクラスをつける | |
--> | |
<tr ng-repeat='restaurant in directory' | |
ng-click='selectRestaulant($index)' | |
ng-class='{selected: $index==selectedRow}'> | |
<td>{{restaurant.name}}</td> | |
<td>{{restaurant.cuisine}}</td> | |
</tr> | |
</table> | |
<script src="../bower_components/angular/angular.js"></script> | |
<script> | |
function RestaurantTableController($scope) { | |
$scope.directory = [ | |
{name: 'The Handsome Heifer', cuisine:'BBQ'}, | |
{name: 'Green\'s Green Greend', cuisine:'Salads'}, | |
{name: 'House of Fine Fish', cuisine:'Seafood'} | |
]; | |
$scope.selectRestaulant = function(row) { | |
$scope.selectedRow = row; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment