-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTicket.ts
40 lines (37 loc) · 1.1 KB
/
Ticket.ts
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
import {Component, ChangeDetectionStrategy, OnInit, NgZone, ChangeDetectorRef, Input} from '@angular/core';
import { Subscription } from 'rxjs';
import {TicketModel} from './LottoPicker';
import 'rxjs/add/operator/timeInterval';
@Component(
{
selector: 'ticket',
providers: [],
styles: ['.ticket { float: left; border: 1px solid black; margin: 5px; padding: 2px; font-size: 16px; }'],
template: `
<div class="ticket">
TicketId: {{model.ticketId}}
<br />
{{interval}} {{model.pick}}
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush
}
)
export class Ticket implements OnInit {
private subscription: Subscription;
@Input()
public model: TicketModel;
public interval: number;
constructor(private cd: ChangeDetectorRef, private zone: NgZone) {
cd.detach();
}
ngOnInit() {
this.zone.runOutsideAngular(() => {
this.subscription = this.model.updates$.timeInterval().subscribe((x) => {
this.interval = x.interval;
this.model.updatePick(x.value);
this.cd.detectChanges();
});
});
}
}