Open History to see the last commit
1# TanStack Angular Query RxJS Example
2β
3An autocomplete that debounces input with RxJS and keeps the previous results with `keepPreviousData`.
4β
5## How it works
6β
7- `src/app/services/suggestions/queries.ts` is an `@Injectable` `SuggestionsQueries` whose `list(term)` returns `queryOptions` keyed by `['suggestions', 'list', term]`. `src/app/services/suggestions/api.ts` returns an empty list for a blank term without making a request.
8- `src/app/components/example.component.ts` pipes the form control's `valueChanges` through `debounceTime(300)` and `distinctUntilChanged()`, and turns the result into the `term` signal with `toSignal`.
9- `src/app/components/example.component.ts` then spreads `list(this.term())` into `injectQuery` with `placeholderData: keepPreviousData` and a 5-minute `staleTime`, so the previous suggestions stay on screen while the next term loads.
10- `src/app/interceptor/autocomplete-mock.interceptor.ts` is an `HttpInterceptorFn`, registered with `withInterceptors` in `src/app/app.config.ts`, that answers `/api/autocomplete` with the programming languages starting with the term after 100 to 500 ms.
11β
12To run this example:
13β
14- `npm install`
15- `npm start`