Last active
August 29, 2015 14:27
-
-
Save MacKentoch/a9fb08fa890030237ec5 to your computer and use it in GitHub Desktop.
an angular clock directive
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
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!'); | |
}); | |
} | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a plunker of this clock