From f5924404a787994ac0e6d4cadbae6a7316babb7c Mon Sep 17 00:00:00 2001 From: tim-herbst Date: Wed, 30 Dec 2020 15:26:11 +0100 Subject: [PATCH] mea culpa mi dominus --- .../app/map/auto-refresh/auto-refresh.component.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/projects/project-3/frontend/src/app/map/auto-refresh/auto-refresh.component.ts b/projects/project-3/frontend/src/app/map/auto-refresh/auto-refresh.component.ts index 4f0a528..477d29f 100644 --- a/projects/project-3/frontend/src/app/map/auto-refresh/auto-refresh.component.ts +++ b/projects/project-3/frontend/src/app/map/auto-refresh/auto-refresh.component.ts @@ -1,13 +1,15 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnDestroy, OnInit} from '@angular/core'; import {MapService} from '../../service/map.service'; +import * as internal from 'events'; @Component({ selector: 'app-auto-refresh', templateUrl: './auto-refresh.component.html', styleUrls: ['./auto-refresh.component.scss'] }) -export class AutoRefreshComponent implements OnInit { +export class AutoRefreshComponent implements OnInit, OnDestroy { isFlagActive: boolean; + interval: internal; constructor(private map: MapService) { const storageFlag = JSON.parse(sessionStorage.getItem('auto-refresh')); @@ -19,15 +21,19 @@ export class AutoRefreshComponent implements OnInit { } ngOnInit(): void { - setInterval(() => { + this.interval = setInterval(() => { if (this.isFlagActive) { this.map.autoRefresh(); } }, 30000); } + ngOnDestroy(): void { + clearInterval(this.interval); + } onChange(flag: boolean): void { sessionStorage.setItem('auto-refresh', JSON.stringify(flag)); } + }