【发布时间】:2018-03-07 11:37:58
【问题描述】:
我正在尝试在 Angular 5 函数上使用 debounceTime,但我不确定如何使用它。当我构建一个搜索功能时,我可以使用它,因为它绑定到对该输入值所做的更改,如下所示:
this.search
.debounceTime(400)
.distinctUntilChanged()
.takeUntil(this.onDestroy)
.subscribe((model) => {
return this.filterArray(model);
});
但是现在我想把它应用到一个函数中,这个函数从很多地方被调用,并通过http post向数据库发送一个事件,像这样:
private saveData(): void {
this.http.post('event/url', data).takeUntil(this.onDestroy).subscribe((response: Response) => {
// -
}, error => {
// -
});
}
有没有办法像saveData().debounceTime() 那样做,或者我需要用其他方法吗?
【问题讨论】: