# Stop/Restart $timeout when change and return to view

**URL:** <https://forum.ionicframework.com/t/stop-restart-timeout-when-change-and-return-to-view/33004>\
**Category:** ionic-v1\
**Created:** [September 23, 2015, 8:06am UTC](https://forum.ionicframework.com/t/stop-restart-timeout-when-change-and-return-to-view/33004 "2015-09-23T08:06:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ingalb](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@ingalb](https://forum.ionicframework.com/u/ingalb)\
**Post date:** [September 23, 2015, 8:06am UTC](https://forum.ionicframework.com/t/stop-restart-timeout-when-change-and-return-to-view/33004/1 "2015-09-23T08:06:32Z")

</div>

Hello,

I have a View that is updated after 1 minute, I stop the timer after before leaving this view, and all is OK.  
After returning to the current view the timer don’t restart again.

This is the code of the controller of this view:

```
.controller('IndexCtrl', function($scope, $timeout, RestService) {
    var updateN = 60*1000;
    $scope.test = "View 1 - Update";
    var update = function update() {
         timer = $timeout(update, updateN);
         / **make a http call to Rest API service and get data** /
        RestService.getdata(function(data) {;
             $scope.items = data.slice(0,2);
         });
    }();
    
   / **Stop the timer before leave the view** /
    $scope.$on('$ionicView.beforeLeave', function(){
   $timeout.cancel(timer);
      //alert("Before Leave");
   });  

   / **Restart timer** /
    $scope.$on('$ionicView.enter', function(){
    $timeout(update, updateN);
      //alert("Enter");
   }); 
})

.controller('ViewCtrl2', function($scope) {

  $scope.test = "View 2";

});

```

What I’m missing ?

Thanks
