首页 > 解决方案 > 如何设置输入延迟并防止在 Angular 中对空输入请求 api?

问题描述

我遇到了这个问题,在空输入时想要停止请求 API,并且在用户停止输入后输入设置延迟

searchBrands(searchedBrand) {
const term = searchedBrand.target.value
if (term === '') {

}
setTimeout(() => {
  this.brandsTagsService.getBrands({
    term
  }).subscribe((data: IAllBrands[]) => {
    this.allBrands = data;
  })
},2000)
}
}

标签: angularfunctionapidelay

解决方案


推荐阅读