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?
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_);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With