Created
April 25, 2014 20:40
-
-
Save carloscarcamo/11302539 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>CSS Classes and Styles | |
</title> | |
<style> | |
.error{background-color:red;} | |
.warning{background-color:yellow;} | |
.selected{background-color:lightgreen | |
;} | |
</style> | |
</head> | |
<body ng-app="stylesModule"> | |
<div ng-controller='HeaderController'> | |
<div ng-class='{error:isError, warning:isWarning}'> | |
{{messageText}} | |
</div> | |
<button ng-click='showError()'>Simulate Error</button> | |
<button ng-click='showWarning()'>Simulate Warning</button> | |
</div> | |
<br><br> | |
<table ng-controller='RestaurantTableController'> | |
<tr ng-repeat='restaurant in directory' ng-click='selectRestaurant($index)' | |
ng-class='{selected: $index==selectedRow}'> | |
<td>{{restaurant.name}}</td> | |
<td>{{restaurant.cuisine}}</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
This file contains 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
var stylesModule = angular.module('stylesModule', []); | |
stylesModule.controller('HeaderController', ['$scope', | |
function($scope){ | |
$scope.isError = false; | |
$scope.isWarning = false; | |
$scope.showError = function(){ | |
$scope.messageText = "This is an error!"; | |
$scope.isError = true; | |
$scope.isWarning = false; | |
}; | |
$scope.showWarning = function(){ | |
$scope.messageText = "This is a warning!"; | |
$scope.isWarning = true; | |
$scope.isError = false; | |
}; | |
} | |
]); | |
stylesModule.controller('RestaurantTableController', ['$scope', function($scope){ | |
$scope.directory = [ | |
{name:'The Handsome Heifer', cuisine:'BBQ'}, | |
{name:"Green's Green Greens", cuisine:'Salads'}, | |
{name:'House of Fine Fish', cuisine:'Seafood'} | |
]; | |
$scope.selectRestaurant = function(row){ | |
$scope.selectedRow = row; | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment