小编CNI*_*NIS的帖子

如何在 Angular 中执行函数之前等待最后一次击键?

我有以下输入:

 <input type="text" placeholder="Search for new results" (input)="constructNewGrid($event)" (keydown.backslash)="constructNewGrid($event)">
Run Code Online (Sandbox Code Playgroud)

和功能

constructNewGrid(e){
    // I want to wait 300ms after the last keystroke before constructing the new grid
    // If the passed time is <300ms just return without doing something
    // else start constructing new grid
}
Run Code Online (Sandbox Code Playgroud)

我不太确定如何建立这样的条件。我应该如何解决这个问题?我在 RxJS 中阅读了关于 debounceTime 的内容,这正是我想要的,但我没有在函数中使用 observable,所以:你将如何在函数中构建这样的条件?

html input rxjs typescript angular

0
推荐指数
1
解决办法
632
查看次数

标签 统计

angular ×1

html ×1

input ×1

rxjs ×1

typescript ×1