1 import { Component, OnInit, OnDestroy } from '@angular/core';
3 import { RequestService, RequestStats } from '../shared';
6 selector: 'my-request-stats',
7 templateUrl: './request-stats.component.html',
8 styleUrls: [ './request-stats.component.scss' ]
10 export class RequestStatsComponent implements OnInit, OnDestroy {
11 stats: RequestStats = null;
13 private interval: NodeJS.Timer = null;
15 constructor(private requestService: RequestService) { }
22 if (this.stats !== null && this.stats.secondsInterval !== null) {
23 clearInterval(this.interval);
28 this.requestService.getStats().subscribe(
34 err => alert(err.text)
38 private runInterval() {
39 this.interval = setInterval(() => {
40 this.stats.remainingMilliSeconds -= 1000;
42 if (this.stats.remainingMilliSeconds <= 0) {
43 setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100);
44 clearInterval(this.interval);