title: Stop $timeout when starting new controller
body: <p>I'm polling for my data every 2 seconds to keep them updated on the page. My problem is when I visit another page the timeout stays active. How can i cancel my timeout when I visit an new page?</p>
  
  <pre><code>function IndexCtrl($scope, $timeout, RestData) {
      $scope.rd = {};
  
      (function getRestDataFromServer() {
          RestData.query(function(data){
              $scope.rd = data;
              $timeout(getRestDataFromServer, 2000);
          });
      })();
  }
  </code></pre>
  
  <p>//EDIT
  I found a solution, but I'm not sure if it's a good one. When i save my timeout to the $rootScope, I can cancel it in all the other controllers.</p>
  
  <pre><code>function IndexCtrl($scope, $rootScope, $timeout, RestData) {
      $scope.rd = {};
  
      (function getRestDataFromServer() {
          RestData.query(function(data){
              $scope.rd = data;
              $rootScope.prom = $timeout(getRestDataFromServer, 2000);
          });
      })();
  }
  
  function newPageCtrl($scope, $rootScope, $timeout) {
      $timeout.cancel($rootScope.prom); 
  }
  </code></pre>