-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangularjs.js
More file actions
59 lines (50 loc) · 1.58 KB
/
angularjs.js
File metadata and controls
59 lines (50 loc) · 1.58 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
app.filter('dateFromNow', function() {
return function(date) {
if (!moment) {
console.log('Error: momentJS is not loaded as a global');
return '!momentJS';
}
return moment(date).fromNow();
}
});
app.directive("fileread", [() => ({
scope: {
fileread: "="
},
link(scope, element, attributes) {
element.bind("change", changeEvent => {
const reader = new FileReader();
reader.onload = loadEvent => {
scope.$apply(() => {
scope.fileread = loadEvent.target.result;
});
}
reader.readAsDataURL(changeEvent.target.files[0]);
});
}
})]);
app.directive('time', [
'$timeout',
'$filter',
function($timeout, $filter) {
return function(scope, element, attrs) {
var time = attrs.time;
var intervalLength = 1000 * 10; // 10 seconds
var filter = $filter('dateFromNow');
function updateTime() {
element.text(filter(time));
}
function updateLater() {
timeoutId = $timeout(function() {
updateTime();
updateLater();
}, intervalLength);
}
element.bind('$destroy', function() {
$timeout.cancel(timeoutId);
});
updateTime();
updateLater();
};
}
]);