Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How do you reset a $timeout, and disable a $watch().

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.45k
    Comment on it

    To cleanup the timeout, just use ".cancel()":

    var customTimeout = $timeout(function () {
      // your code
    }, 55);
    
    $timeout.cancel(customTimeout);
    

    The same applies to $interval().

    To disable a watch, just call it.

    // .$watch() returns a deregistration function that we store to a variable
    var deregisterWatchFn = $rootScope.$watch(anyGloballyAvailableProperty, function (newValue) {
      if (newValue) {
        // we invoke that deregistration function, to disable the watch
        deregisterWatchFn();
        //your code
      }
    });
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: