How to implement a debounce time in keyup event in Angular 6

后端 未结 7 2020
盖世英雄少女心
盖世英雄少女心 2020-12-05 17:57

I create an Angular app that search students from API. It works fine but it calls API every time an input value is changed. I\'ve done a research that I need something calle

7条回答
  •  执笔经年
    2020-12-05 18:20

    For anyone coming across this in a newer version of angular (and rxjs).

    The new Rxjs has pipeable operators and they can be used like this (from the accepted answers code)

    ngOnInit() {
     this.subscription = this.searchTextChanged.pipe(
       debounceTime(1000),
       distinctUntilChanged(),
       mergeMap(search => this.getValues())
      ).subscribe((res) => {
        console.log(res);
      });
    

提交回复
热议问题