【问题标题】:AngularJS: timeout doesn't workAngularJS:超时不起作用
【发布时间】:2017-08-07 16:07:26
【问题描述】:

我是 AngularJS 的新手。我的控制器中有这段代码:

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

在我的模板中,我使用:ng-click="parent.setId(id)"timeout 似乎不起作用。为什么?

【问题讨论】:

  • 控制台有错误吗?
  • 不,没有任何错误。
  • setId() 被执行了吗?
  • 是的,只是超时无效。

标签: javascript angularjs ecmascript-6 timeout


【解决方案1】:

尝试将TIMELAPSE_ 作为第二个参数解析为$timeout 函数,你会没事的。看到这个runnable fiddle

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 2015-11-08
    • 2018-12-27
    • 2012-05-15
    • 2011-02-21
    • 1970-01-01
    • 2011-09-09
    相关资源
    最近更新 更多