去反弹时间 api 调用和表单重置角度 9.



我需要有一个重置按钮来搜索,但要有去抖动。 这就是我目前拥有的。 我相信我的问题是,一旦重置,我就会失去表格的"这个"。

searchForm = new FormControl('');
constructor(private searchService: SearchService){}
ngOnInit(): void {
this.searchForm.valueChanges.pipe(
debounceTime(500),
distinctUntilChanged())
.subscribe(() => {
this.getSearch();
});
}
getSearch(){
this.searchService.getSearch(this.searchForm.value).subscribe( res => console.log(res);
}
onReset(){
this.searchForm.reset();
}

我是 Angular 的新手,我相信这很糟糕,我感谢您的帮助。

将重置事件更改为 :-

onReset(){
this.searchForm.reset(null, {emitEvent: false, onlySelf: true});
}

这将防止对您的值更改发出此更改,并且不会影响您的去抖动时间左右。

最新更新