javascriptangulartypescriptrxjsangular-resource

Debouncing a search term when using the new Angular Resource API?


With RxJS we could debounce keystrokes like this prior to performing an http request.

this.query$.pipe(
    debounceTime(500),
    distinctUntilChanged(),

Does the new Angular Resource API have a way to debounce an input field prior to updating request parameters?


Solution

  • ATM (19.0) there is no debouncing support with resource/rxResource, you'll have to build this in userland.

    resource is primarly a primitive that we can build upon. The whole fetch data story isn't complete yet.

    What you could do is :

    inputStr = toSignal(this.query$.pipe(
        debounceTime(500),
        distinctUntilChanged())
    ); 
    
    resource({
      request: this.inputStr;
      loader: (param) => { ... }
    });