examples/angular/pagination
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Angular Query Pagination Example#
Paginated projects with placeholderData: keepPreviousData, so the current page stays visible while the next one loads. The next page is prefetched.
How it works#
src/app/services/projects/queries.tsis an@InjectableProjectsQuerieswhoselist(page)returnsqueryOptionskeyed by['projects', 'list', page], converting theHttpClientcall fromsrc/app/services/projects/api.tswithlastValueFrom.src/app/components/example.component.tsspreadslist(this.page())intoinjectQuerywithplaceholderData: keepPreviousDataand a 5-secondstaleTime. While the next page loads,data()still holds the previous page andisPlaceholderData()istrue, which disables the "Next Page" button.- An
effectinsrc/app/components/example.component.tsfetches the next page ahead of time withqueryClient.query(this.#projectsQueries.list(newPage))when the current page hashasMore: trueand is not placeholder data. src/app/interceptor/projects-mock.interceptor.tsis anHttpInterceptorFn, registered withwithInterceptorsinsrc/app/app.config.ts, that answers/api/projectswith 10 projects per page after a 1-second delay.
To run this example:
npm installnpm start