-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-current-time.js
34 lines (30 loc) · 1.02 KB
/
angular-current-time.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(function(window, angular, undefined) {'use strict';
/**
* @module currentTime
*
* @description Displays continuously the current time in the given format
*
* @usage <h5 current-time="'dd/MM/yyyy HH:mm'"/>
*/
angular.module('currentTime', [])
.directive("currentTime", function(dateFilter) {
return function(scope, element, attrs) {
var format;
scope.$watch(attrs.currentTime, function(value) {
format = value;
updateTime();
});
function updateTime() {
var dt = dateFilter(new Date(), format);
element.text(dt);
}
function updateLater() {
setTimeout(function() {
updateTime(); // update DOM
updateLater(); // schedule another update
}, 1000);
}
updateLater();
}
})
})(window, window.angular);