Stop time interval during navigation in angularjs

From the angularjs example in the $interval API page.

    var interval = $interval(function() {
        console.log('say hello');
    }, 1000);

    $interval.cancel(interval);

With $interval.cancel(var) you can stop the interval and if you want to stop it when navigating to another page you should try something like this.

var interval = null;

module.controller('SomeController', '$interval', function($interval) {
    interval = $interval(function() {
        ...
    }, 2000);
}).run(['$rootScope', '$interval', function($rootScope, $interval) {
    $rootScope.$on('$routeChangeStart', function() {
        $interval.cancel(interval);
    });
}]);

You can listen to the $routeChangeStart event and do the clearing of the interval depending on the route parameters,

  $scope.$on('$routeChangeStart', function (scope, next, current) {
           if(<next is not default.aspx>){
           // clear interval here
            }
  });