2

I use angular $time out to reload data from api and show live statistic in dom. Reload works very well, make reload after 5 sec. But problem is, after i click on another tab, where i don't need $timeout and reload data, there is still reloading data same like on page before. That data is not in DOM, but in network console still reloading data from code bellow, and call http get url with that data.

$scope.reload = function () {
$http.get(serviceBase + 'live-stats').
    success(function (res) {
         $scope.proizvedeno = res;
console.log(res);  
         });
         $timeout(function(){
            $scope.reload();
            }, 5000);
    };
            $scope.reload(); 

P.S. i use angular-loading-bar, is there any way to this bar does not rotate when reload only a certain part of the page, in this case retrieve data from the "timeout" to display statistics

EDIT: i add this to this ctrl

$scope.reload = function () {
$http.get(serviceBase + 'live-stats').
    success(function (res) {
         $scope.proizvedeno = res;
console.log(res);  
         });
         $timeout(function(){
            $scope.reload();
            }, 5000);
 $scope.$on('$destroy', function(){    //this is what i add
$timeout.cancel(reload);             //this is what i add
    };
            $scope.reload(); 

but still timeout not canceled

1 Answer 1

1

i only need to declare "var reload"

var reload = $timeout(function(){
            $scope.reload();
            }, 5000);
            $scope.$on('$destroy', function(){
$timeout.cancel(reload);

});

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.