angular - 如何设置输入延迟并防止在 Angular 中对空输入请求 api?
问题描述
我遇到了这个问题,在空输入时想要停止请求 API,并且在用户停止输入后输入设置延迟
searchBrands(searchedBrand) {
const term = searchedBrand.target.value
if (term === '') {
}
setTimeout(() => {
this.brandsTagsService.getBrands({
term
}).subscribe((data: IAllBrands[]) => {
this.allBrands = data;
})
},2000)
}
}
解决方案
推荐阅读
- laravel - 提交时清空购物车内容
- java - com.google.firebase.database.DatabaseException:发现两个 getter 或属性的区分大小写冲突的字段:名称
- c# - Visual Studio 编译错误 - 计算机中缺少 nuget 包,但 nuget restore 说所有包都已安装?
- python - 使用 2 个参数计算列表中单词的函数
- c# - ILDASM和ILASM,如何使用它们?
- android - 如何使用 NFC 发送简单的字符串
- javascript - 如何将变量传递给另一个php文件?
- flutter - 在模拟器中查看 Flutter 小部件测试
- database - 使用 Parse Server 的社交网络应用程序的数据库建议
- json - Python json 错误列表索引必须是整数