Here is such an interesting problem. There is the first page that opens when it opens and makes a request to the API and how I need to repeat it every 5 seconds. Only here is the problem .. if I left the page, then my requests continue to work. I use it like this
$scope.getData(); $interval(function () { $scope.getData(); }, 5000);
Well, firstly, you need to strain the browser and backend with an extra request that is not needed. He does not see the page ... And secondly, I plan another 5 pages at least where the requests will go every 5 seconds to the services, and that's how I write so that the request only went when the user went to the pages. Immediately came the idea that you can check the current state like this.
if ($state.current.name = 'home')
and here I was surprised .. for him this state remained Home and I’ve already been to another .. so it didn’t help. What to do?