My search field will run the following function on (change)="onSearch($event)"
onSearch(q) {
console.log('started search')
const self = this;
let timeout = null;
clearTimeout(timeout);
timeout = setTimeout(() => {
self._results = self.bcProductService.getProducts_packed({'keyword':q}).subscribe( (results)=> {
_log(' == Results ==> ','bc', results.data);
self.results = results.data;
});
self.searchText = q;
}, 3000);
}
as you can see. I am trying to only run the function once if no activity for 3 seconds. But it is actually running once for every (change) event. How can i write rewrite this function to only run once for every pause instead of every-time they type.
Comments
Post a Comment