I tried to use the function _.debounce in lodash library in my angular app.
my code:
onKeyup(event) {
if (event.length >= 3) {
this.getCities(event);
}
}
public getCities(namePrefix: any) {
this.citiesSrv.getCities(namePrefix).toPromise().catch(err => console.log(err)).then(results => {
this.options = results["data"].map(x => x.name + ", " + x.country);
}
).then(test => {
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith(''),
map(value => this._filter(value))
);
})
}
I want to call getCities in OnKeyup function in delay. What is the right way?
thanks
you need to wrap
debouncearoundgetCitiesand the call it. So inside your component file In code snippet below I have debounce it to 400 ms