Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: timeout doesn't work

I'm new to AngularJS. I have this code in my controller:

let timeout_ = false;
let TIMELAPSE_ = 2000;
vm.setId= function (id) {
   $timeout.cancel(timeout_);
   timeout_ = $timeout(() => { SearchService.setId(id), TIMELAPSE_});
};

In my template I use: ng-click="parent.setId(id)". The timeout doesn't seem to work. Why?

like image 258
Anna Avatar asked May 22 '26 04:05

Anna


1 Answers

Try to parse TIMELAPSE_ as second parameter into $timeout function and you will be fine. See this runnable fiddle.

let timeout_ = false;
let TIMELAPSE_ = 2000;
vm.setId= function (id) {
   $timeout.cancel(timeout_);
   timeout_ = $timeout(() => { SearchService.setId(id)}, TIMELAPSE_);
};
like image 200
lin Avatar answered May 24 '26 18:05

lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!