AngularJS Example
by basarat
HTML
<div ng-app="time">
<div>Current time is: <span my-current-time></span>
<br/>
</div>
</div>
CSS
</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> <style> .ng-invalid {
border: 1px solid red;
}
JavaScript
angular.module('time', [])
.directive('myCurrentTime', function ($timeout) {
return function (scope, element, attrs) {
// schedule update in one second
function updateLater() {
$timeout(function () {
element.text(new Date());
updateLater(); // schedule another update
}, 1000);
}
updateLater(); // kick off the UI update process.
}
});