{{ post.title }}
+{{ post.body }}
+{{ data.description }}
👀 {{ data.subscribers_count }} diff --git a/docs/framework/angular/quick-start.md b/docs/framework/angular/quick-start.md index cfe29d87b58..c7358a767af 100644 --- a/docs/framework/angular/quick-start.md +++ b/docs/framework/angular/quick-start.md @@ -3,42 +3,25 @@ id: quick-start title: Quick Start --- -> IMPORTANT: This library is currently in an experimental stage. This means that breaking changes will happen in minor AND patch releases. Upgrade carefully. If you use this in production while in experimental stage, please lock your version to a patch-level version to avoid unexpected breaking changes. - [//]: # 'Example' If you're looking for a fully functioning example, please have a look at our [basic codesandbox example](./examples/basic) -### Provide the client to your App +### Configure the QueryClient -```ts -import { provideHttpClient } from '@angular/common/http' -import { - provideTanStackQuery, - QueryClient, -} from '@tanstack/angular-query-experimental' - -bootstrapApplication(AppComponent, { - providers: [provideHttpClient(), provideTanStackQuery(new QueryClient())], -}) -``` - -or in a NgModule-based app +Pass a factory to `provideTanStackQuery`. Angular runs it once per injector and in an injection context, so it can use `inject()`. ```ts import { provideHttpClient } from '@angular/common/http' -import { - provideTanStackQuery, - QueryClient, -} from '@tanstack/angular-query-experimental' +import { bootstrapApplication } from '@angular/platform-browser' +import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query' -@NgModule({ - declarations: [AppComponent], - imports: [BrowserModule], - providers: [provideTanStackQuery(new QueryClient())], - bootstrap: [AppComponent], +bootstrapApplication(AppComponent, { + providers: [ + provideHttpClient(), + provideTanStackQuery(() => new QueryClient()), + ], }) -export class AppModule {} ``` ### Component with query and mutation @@ -52,7 +35,7 @@ import { injectMutation, injectQuery, QueryClient, -} from '@tanstack/angular-query-experimental' +} from '@tanstack/angular-query' @Component({ template: ` diff --git a/docs/framework/angular/reference/functions/infiniteQueryOptions.md b/docs/framework/angular/reference/functions/infiniteQueryOptions.md index 1011653b452..263900df70a 100644 --- a/docs/framework/angular/reference/functions/infiniteQueryOptions.md +++ b/docs/framework/angular/reference/functions/infiniteQueryOptions.md @@ -9,7 +9,7 @@ title: infiniteQueryOptions function infiniteQueryOptions+ Devtools load in development automatically. For a production build, press + ⌘CtrlShiftD once to load them. +
+ +@if (query.isPending()) { +{{ data.description }}
+ 👀 {{ data.subscribers_count }} + ✨ {{ data.stargazers_count }} + 🍴 {{ data.forks_count }} +} diff --git a/examples/angular/dynamic-devtools/src/app/components/dynamic-devtools-example.component.ts b/examples/angular/dynamic-devtools/src/app/components/dynamic-devtools-example.component.ts new file mode 100644 index 00000000000..e810f3ec773 --- /dev/null +++ b/examples/angular/dynamic-devtools/src/app/components/dynamic-devtools-example.component.ts @@ -0,0 +1,29 @@ +import { HttpClient } from '@angular/common/http' +import { ChangeDetectionStrategy, Component, inject } from '@angular/core' +import { injectQuery } from '@tanstack/angular-query' +import { lastValueFrom } from 'rxjs' + +interface Response { + name: string + description: string + subscribers_count: number + stargazers_count: number + forks_count: number +} + +@Component({ + changeDetection: ChangeDetectionStrategy.OnPush, + selector: 'dynamic-devtools-example', + templateUrl: './dynamic-devtools-example.component.html', +}) +export class DynamicDevtoolsExampleComponent { + readonly #http = inject(HttpClient) + + readonly query = injectQuery(() => ({ + queryKey: ['repoData'], + queryFn: () => + lastValueFrom( + this.#http.get
+ Each item below owns one entry in injectQueries. Add or
+ remove items to change the query list.
+
No items. Add one to start a query.
+ } @else { +Angular SSR + client-only island + persistence
+
+ Posts use queryKey: ['posts'] and run on the server.
+ Configure the persister with
+ dehydrateOptions.shouldDehydrateQuery if you want only
+ client-persist keys in localStorage.
+
+ The panel below is mounted only in the browser via
+ afterNextRender, so its query never runs during SSR.
+ After the first visit, hard-reload: the timestamp can be restored from
+ persistence while posts render from SSR again.
+
+ Server render: this placeholder has no
+ client-persist-demo component yet — it is created after
+ the first browser frame via afterNextRender.
+
Client-only island
+Loading client-only data…
+ } @else if (demo.isError()) { +Failed to load.
+ } @else if (demo.data(); as data) { +{{ data.createdAt }}
+
+ This value is stored under the client-persist query key.
+ Hard-reload the page: it should reappear from persistence while the
+ posts list above is rendered from SSR again.
+
Loading posts...
+ } @else if (postsQuery.isError()) { +Failed to load posts.
+ } @else { +{{ post.body }}
+Angular SSR
++ The first render comes from the server. Angular then hydrates the app + on the client and TanStack Query continues from a fresh client cache. +
+Loading posts...
+ } @else if (postsQuery.isError()) { +Failed to load posts.
+ } @else { +{{ post.body }}
+
+ Signal Forms uses a Resource backed by TanStack Query for async
+ validation. Try taken or any other username.
+