您可以像https://stackblitz.com/edit/angular-debounce-form-control中的示例一样使用rxjs debounceTime管道连接到valueChanges反应器的observableFormControl
逻辑是使用FormControl并订阅该valueChanges方法来获取对输入的引用,并通过管道 adebounceTime仅在特定时间间隔内未触发时触发回调方法。
this.searchControl.valueChanges
.pipe(
debounceTime(2000),
distinctUntilChanged()
)
.subscribe(res => {
//your API call
});
Run Code Online (Sandbox Code Playgroud)
这里distinctUntilChanged()使订阅回调仅在发出不同的值时执行。
| 归档时间: |
|
| 查看次数: |
3009 次 |
| 最近记录: |