Open History to see the last commit
1---
2id: background-fetching-indicators
3title: Background Fetching Indicators
4ref: docs/react/guides/background-fetching-indicators.md
5---
6β
7[//]: # 'Example'
8β
9```ts
10@Component({
11 selector: 'posts',
12 template: `
13 @switch (query.status()) {
14 @case ('pending') {
15 Loading...
16 }
17 @case ('error') {
18 An error has occurred: {{ query.error()?.message }}
19 }
20 @default {
21 @if (query.isFetching()) {
22 Refreshing...
23 }
24 @for (todo of query.data()) {
25 <todo [todo]="todo" />
26 }
27 }
28 }
29 `,
30})
31export class TodosComponent {
32 todosQuery = injectQuery(() => ({
33 queryKey: ['todos'],
34 queryFn: fetchTodos,
35 }))
36}
37```
38β
39[//]: # 'Example'
40[//]: # 'Example2'
41β
42```ts
43import { injectIsFetching } from '@tanstack/angular-query-experimental'
44β
45@Component({
46 selector: 'global-loading-indicator',
47 template: `
48 @if (isFetching()) {
49 <div>Queries are fetching in the background...</div>
50 }
51 `,
52})
53export class GlobalLoadingIndicatorComponent {
54 isFetching = injectIsFetching()
55}
56```
57β
58[//]: # 'Example2'