Created
September 27, 2013 14:33
-
-
Save jepetko/6729530 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
#weather { | |
font-size: 20px; | |
font-weight: bold; | |
border: 2px solid black; | |
padding: 20px; | |
} | |
.rainy { | |
background: blue; | |
color: white; | |
} | |
.rainy:after { | |
content: ' I need an umbrella. Its rainy.'; | |
} | |
.sunny { | |
background: yellow; | |
color: black; | |
} | |
.sunny:after { | |
content: ' The sun is shining. Thats pretty.' | |
} | |
.hot { | |
background: red; | |
color: white; | |
} | |
.hot:after { | |
content: ' Its extremely hot here!'; | |
} | |
.cold { | |
background: white; | |
color: grey; | |
} | |
.cold:after { | |
content: ' Its winter. Brrrr....' | |
} |
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="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
<meta name="description" content="AngularJS Directives" /> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="weather-app" ng-app="weatherApp"> | |
The following div is able to tell you the weather. | |
<div id="weather" data-add-weather-forcast>Your forcast! </div> | |
</div> | |
</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 weatherApp = angular.module('weatherApp',[]); | |
weatherApp.directive('addWeatherForcast', function($timeout) { | |
return function(scope,element, attrs) { | |
$timeout(function() { | |
var forcasts = [ 'rainy', 'sunny', 'hot', 'cold' ]; | |
var random = Math.floor(Math.random() * forcasts.length); | |
element.removeClass(); | |
var el = $(element); | |
el.addClass(forcasts[random]); | |
}, 500); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment