3

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?

4
  • any errors in console? Commented Mar 16, 2017 at 13:01
  • Nope, not any error. Commented Mar 16, 2017 at 13:04
  • setId() is executed? Commented Mar 16, 2017 at 13:05
  • Yes, it's only the timeout that is ineffective. Commented Mar 16, 2017 at 13:06

1 Answer 1

3

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_);
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.