angular11 搜索 防抖 节流 实时搜索

// ts 文件代码
 
import { Subject } from 'rxjs';
import { debounceTime,map,takeUntil } from "rxjs/operators";
 
  destroy$ = new Subject();
  searchTbNameChange$ = new Subject();
 
  ngOnInit() {
    this.searchTbNameChange$.pipe(
      debounceTime(500),
      map( e => this.queryParam.tb_name.trim()), // 删除字符串左右空格
      takeUntil(this.destroy$)
    ).subscribe((res) => {
      this.queryDBTaskList(); // 具体需要防抖的函数
    });
  }
 
 
// html中调用
 
(ngModelChange)="searchTbNameChange$.next()"
————————————————
版权声明:本文为CSDN博主「xggllc」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xggllc/article/details/112714123

 

posted @ 2021-04-01 21:01  jahoon  阅读(195)  评论(0)    收藏  举报