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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -