Open History to see the last commit
1import { Component } from '@angular/core'
2import {
3 QueryClient,
4 injectMutation,
5 injectQuery,
6 provideTanStackQuery,
7} from '@tanstack/angular-query'
8import { withDevtools } from '@tanstack/angular-query-devtools'
9import { withPersistQueryClient } from '@tanstack/angular-query-persist-client'
10import type { ApplicationConfig } from '@angular/core'
11β
12export const appConfig: ApplicationConfig = {
13 providers: [
14 provideTanStackQuery(
15 () => new QueryClient(),
16 withDevtools(() => ({ loadDevtools: false })),
17 withPersistQueryClient(() => ({
18 persistOptions: {
19 persister: {
20 persistClient: () => {},
21 restoreClient: () => undefined,
22 removeClient: () => {},
23 },
24 },
25 })),
26 ),
27 ],
28}
29β
30@Component({
31 standalone: true,
32 template: `
33 @if (query.isSuccess()) {
34 <span>{{ query.data().title }}</span>
35 }
36 <button (click)="mutation.mutate('updated')">
37 {{ mutation.isPending() ? 'Saving' : 'Save' }}
38 </button>
39 `,
40})
41export class AngularCompatibilityComponent {
42 readonly query = injectQuery(() => ({
43 queryKey: ['angular-compatibility'],
44 queryFn: () => Promise.resolve({ title: 'Angular Query' }),
45 }))
46β
47 readonly mutation = injectMutation(() => ({
48 mutationFn: (title: string) => Promise.resolve({ title }),
49 }))
50}