Sunday, October 1, 2017

Is it okay to have a self canceling $timeout?

I am wondering if it’s okay to have a $timeout that cancels itself after it runs. Usually what I see is people saying that you should cancel your $timeout‘s in the $destroy like this:

var timeout = $timeout(function () {
    // stuff
});

$scope.$on("$destroy", function(){
    $timeout.cancel(timeout);
});

But, is it okay to do this instead:

var timeout = $timeout(function () {
    // stuff
    $timeout.cancel(timeout);
});

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/01/is-it-okay-to-have-a-self-canceling-timeout/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment