I need to refresh data of angular component each 30 seconds. I use simple setInterval
:
this.interval = setInterval(() => {
this.refresh(); // api call
}, 10000);
However, this is incorrect, because even when I navigate to another "page" (in angular SPA everything is one page, so it is not really another page), refresh is happening each 30 seconds.
What is the correct way to refresh data every 30 seconds only when on specific page/component?