AngularJS $ instant timeout method instantly

I use the ionic structure and the cordova-plugin-shake plugin to detect device jitter for one of my Android apps that is working fine. But the problem is that after shaking I would like to disable this trembling detection for 30 seconds, for which I am trying to use $timeoutas follows:

$timeout($scope.watchForShake(), 30000);

But somehow for $timeout, regardless of the delay value, it $scope.watchForShake()is executed instantly.

I also tried using setTimeout, but the result is still the same.

+4
source share
2 answers

$timeout ( setTimeout) , - , -.

.watchForTimeout, :

var callbackFn = $scope.watchForTimeout;
$timeout(callbackFn, 30000);

30 callbackFn : callbackFn().

$scope.watchForTimeout , `$ timeout. , ():

var returnVal = $scope.watchForTimeout();
$timeout(returnVal, 300000)
+4
$timeout($scope.watchForShake,30000);

paranthesis $scope.watchForShake.

+3

Source: https://habr.com/ru/post/1609558/


All Articles