Skip to content

Instantly share code, notes, and snippets.

@MacKentoch
Last active August 29, 2015 14:27
Show Gist options
  • Save MacKentoch/a9fb08fa890030237ec5 to your computer and use it in GitHub Desktop.
Save MacKentoch/a9fb08fa890030237ec5 to your computer and use it in GitHub Desktop.
an angular clock directive
angular
.module('edaApp', [])
.directive('edaClock', [
'$timeout',
function($timeout){
/**
* should be in a provider or at least a service
*/
var htmlTemplate = [
'<div class="well">',
' <p>{{clockCtrl.time.raw | date: \'hh:mm:ss\'}}</p>',
'</div>'
].join(' ');
return {
restrict: 'E',
template : htmlTemplate,
controllerAs : 'clockCtrl',
controller : function($timeout){
self = this;
self.time = {};
var oneSecPassed = function(){
self.time.raw = new Date();
$timeout(oneSecPassed, 1000)
};
oneSecPassed();
},
link : function(scope, element, attrs, ctrl, transclude) {
element.on('click', function(event){
event.preventDefault;
console.info('don\'t tap the clock!');
});
}
};
}
]);
@MacKentoch
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment