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)); } + }