[英]AngularJS: timeout doesn't work
I'm new to AngularJS. 我是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)"
. 在我的模板中,我使用:
ng-click="parent.setId(id)"
。 The timeout
doesn't seem to work. timeout
似乎不起作用。 Why? 为什么?
Try to parse TIMELAPSE_
as second parameter into $timeout
function and you will be fine. 尝试将
TIMELAPSE_
作为第二个参数解析为$timeout
函数,你会没事的。 See this runnable fiddle . 看到这个可运动的小提琴 。
let timeout_ = false;
let TIMELAPSE_ = 2000;
vm.setId= function (id) {
$timeout.cancel(timeout_);
timeout_ = $timeout(() => { SearchService.setId(id)}, TIMELAPSE_);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.