javascript - angularJS $timeout executing method instantly -
i using ionic framework , cordova-plugin-shake plugin detect device shaking 1 of android application, working fine. problem after shake disable shaking detection 30 second, trying use $timeout
this:
$timeout($scope.watchforshake(), 30000);
but somehow $timeout
, no matter delay value is, $scope.watchforshake()
executed instantly.
i have tried using settimeout
result still same.
$timeout
(and settimeout
) expect callback function first parameter - function execute after time-out.
if want function .watchfortimeout
execute, pass function first parameter:
var callbackfn = $scope.watchfortimeout; $timeout(callbackfn, 30000);
after 30 seconds, function callbackfn
invoked no parameters: callbackfn()
.
in case, invoking $scope.watchfortimeout
right away, passing return value of function first parameter `$timeout. so, doing (incorrectly) is:
var returnval = $scope.watchfortimeout(); $timeout(returnval, 300000)
Comments
Post a Comment