title: Execute an Angular function only if the current tab is active in the browser
body: <p>I have an angular js function which should be called for every 2 seconds only when the current tab is open in the browser. Is there any way to check whether the current page is active in the browser.</p>
  
  <pre><code>  $scope.callAtInterval = function() {
  
        var url = "http://127.0.0.1/test";
  
          $http.get(url).success( function(response) {
             $scope.initial = response;
  
          },
           function errorCallback(response) {
            $scope.result=response;
                        });
  }
  
  $interval( function(){ $scope.callAtInterval(); }, 5000);
  </code></pre>
  
  <p>}</p>