-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomponent.ts
More file actions
37 lines (33 loc) · 1023 Bytes
/
Copy pathcomponent.ts
File metadata and controls
37 lines (33 loc) · 1023 Bytes
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
//our root app component
import {Component, Attribute} from '@angular/core'
@Component({
selector: 'clock',
templateUrl: 'src/clock/view.html'
})
export class ClockComponent {
private data;
private format;
private timer;
private intervalSet = false;
constructor(@Attribute("format") format, @Attribute("data") data, @Attribute('timer') timer) {
var date, miliseconds;
this.format = format || 'h:mm:s';
this.data = data || new Date();
if(timer) {
if(typeof this.data !== 'Date') {
date = new Date();
} else {
date = this.data;
}
miliseconds = (60 - date.getSeconds()) * 1000;
window.setTimeout(()=>{this.refreshTime();}, miliseconds);
}
}
refreshTime() {
this.data = new Date();
if(!this.intervalSet) {
window.setInterval(()=>{this.refreshTime()}, 60000);
this.intervalSet = true;
}
}
}