Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

injectIsFetching.md

70 lines1.9 KB

1---
2id: injectIsFetching
3title: injectIsFetching
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8```ts
9function injectIsFetching(filters?: () => Omit<QueryFilters, "fetchStatus">): Signal<number>;
10```
11​
12Defined in: [packages/angular-query/src/inject-is-fetching.ts:46](https://github.com/TanStack/query/blob/main/packages/angular-query/src/inject-is-fetching.ts#L46)
13​
14Injects a signal that tracks the number of queries that your application is loading or fetching in the
15background (useful for app-wide loading indicators).
16​
17## Parameters
18​
19### filters?
20​
21() => `Omit`\<[`QueryFilters`](../interfaces/QueryFilters.md), `"fetchStatus"`\>
22​
23A function returning the [QueryFilters](../interfaces/QueryFilters.md) to narrow down the matched queries. Similar
24to `computed` from Angular, this function runs in the reactive context, so signals read inside it
25re-narrow the matched queries.
26​
27<a id="filters-properties"></a>
28​
29#### `filters` properties
30​
31Built from [`QueryFilters`](../interfaces/QueryFilters.md#properties). See the type above for what it changes.
32​
33## Returns
34​
35`Signal`\<`number`\>
36​
37A `Signal` with the number of queries that your application is currently loading or fetching in
38the background.
39​
40## Examples
41​
42```angular-ts
43@Component({
44 selector: 'posts-fetching-indicator',
45 template: `
46 @if (isFetchingPosts()) {
47 <span>Refreshing posts...</span>
48 }
49 `,
50})
51export class PostsFetchingIndicator {
52 // How many queries matching the posts prefix are fetching?
53 readonly isFetchingPosts = injectIsFetching(() => ({ queryKey: ['posts'] }))
55```
56​
57A global loading indicator for any query fetching in the background, not just the ones on screen:
58```angular-ts
59@Component({
60 selector: 'global-loading-indicator',
61 template: `
62 @if (isFetching()) {
63 <div>Queries are fetching in the background...</div>
64 }
65 `,
66})
67export class GlobalLoadingIndicator {
68 readonly isFetching = injectIsFetching()
70```