examples/angular/rxjs
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Angular Query RxJS Example#
An autocomplete that debounces input with RxJS and keeps the previous results with keepPreviousData.
How it works#
src/app/services/suggestions/queries.tsis an@InjectableSuggestionsQuerieswhoselist(term)returnsqueryOptionskeyed by['suggestions', 'list', term].src/app/services/suggestions/api.tsreturns an empty list for a blank term without making a request.src/app/components/example.component.tspipes the form control'svalueChangesthroughdebounceTime(300)anddistinctUntilChanged(), and turns the result into thetermsignal withtoSignal.src/app/components/example.component.tsthen spreadslist(this.term())intoinjectQuerywithplaceholderData: keepPreviousDataand a 5-minutestaleTime, so the previous suggestions stay on screen while the next term loads.src/app/interceptor/autocomplete-mock.interceptor.tsis anHttpInterceptorFn, registered withwithInterceptorsinsrc/app/app.config.ts, that answers/api/autocompletewith the programming languages starting with the term after 100 to 500 ms.
To run this example:
npm installnpm start