mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
|
History
|
||
|---|---|---|
| .. | ||
| .devcontainer | ||
| public | ||
| src | ||
| .gitignore | ||
| angular.json | ||
| eslint.config.js | ||
| package.json | ||
| README.md | ||
| tsconfig.app.json | ||
| tsconfig.json | ||
TanStack Angular Query Basic Example (Angular Router)
The basic posts example with Angular Router, one route per view.
Built with Angular Router.
How it works
src/app/services/posts/api.tsis an@InjectablePostsAPIthat returnsHttpClientobservables for the post list and a single post.src/app/services/posts/queries.tsis an@Injectable({ providedIn: 'root' })class,PostsQueries, whoselist()anddetail(id)returnqueryOptionsand convert the observables withlastValueFrom. Components get it withinject(PostsQueries).src/app/components/posts.component.tsreads the list withinjectQuery(() => this.postsQueries.list()), andsrc/app/components/posts.component.htmllinks each post withrouterLinkand shows it in bold green whenqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)returns data.src/app/components/post.component.tsreceives thepostIdroute param as an input throughwithComponentInputBindingand passes it toinjectQuery(() => this.#postsQueries.detail(this.postId())).src/app/app.routes.tslazy loads both components withloadComponent, andsrc/app/app.config.tssets upprovideRouterandprovideTanStackQuerywithwithDevtools().
To run this example:
npm installnpm start