1

I have written an angular application in which im making http calls on each modelChange event. I have used lodash _.debounce(). The issue is im not able to cancel these calls after the first successful execution of debounce.

  modelChangeEvent(item):void {
   const _this = this;
   let debounceObj = _.debounce(function(){
     _this.makeHttpCall(item);
     debounceObj.cancel();
    },600);
  debounceObj();
  }

https://lodash.com/docs/4.17.15#debounce

Nithin P.H
  • 671
  • 1
  • 9
  • 29

1 Answers1

0

Implemented using Rxjs debounceTime() and distinctUntilChanged()

detectInput:any = new Subject();

ngOnInit(){
  this.detectInput.pipe(debounceTime(400),distinctUntilChanged()).subscribe(value=>{
    this.makeHttpCall(value)
  })
}

modelChangeEvent(item):void {
 this.detectInput.next(item);
}
Nithin P.H
  • 671
  • 1
  • 9
  • 29