I'm trying to use debounceTime on an Angular 5 function but I'm not sure how to use it. When I built a search function I could use it, because it was bind to the changes made on that input value, like this:
this.search
.debounceTime(400)
.distinctUntilChanged()
.takeUntil(this.onDestroy)
.subscribe((model) => {
return this.filterArray(model);
});
But now I want to apply it to a function, this function is called from many places, and send an event to the database via http post, something like this:
private saveData(): void {
this.http.post('event/url', data).takeUntil(this.onDestroy).subscribe((response: Response) => {
// -
}, error => {
// -
});
}
Is there a way to do it like saveData().debounceTime()
Or do I need to do it other way?