Open History to see the last commit
1---
2id: injectIsFetching
3title: injectIsFetching
4---
5β
6```ts
7function injectIsFetching(filters?: QueryFilters<readonly unknown[]>, options?: InjectIsFetchingOptions): Signal<number>;
8```
9β
10Defined in: [packages/angular-query-experimental/src/inject-is-fetching.ts:63](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-fetching.ts#L63)
11β
12Injects a signal that tracks the number of queries that your application is loading or fetching in the
13background (useful for app-wide loading indicators).
14β
15## Parameters
16β
17### filters?
18β
19[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>
20β
21The [QueryFilters](../interfaces/QueryFilters.md) to narrow down the matched queries.
22β
23<a id="filters-properties"></a>
24β
25#### `filters` properties
26β
27| Property | Type | Default value | Description |
28| ------ | ------ | ------ | ------ |
29| <a id="filters-property-exact"></a> `exact?` | `boolean` | `undefined` | Match query key exactly |
30| <a id="filters-property-fetchstatus"></a> `fetchStatus?` | `"fetching"` \| `"paused"` \| `"idle"` | `undefined` | Include queries matching their fetchStatus |
31| <a id="filters-property-predicate"></a> `predicate?` | (`query`: [`Query`](../classes/Query.md)) => `boolean` | `undefined` | Include queries matching this predicate function |
32| <a id="filters-property-querykey"></a> `queryKey?` | `TQueryKey` \| `TuplePrefixes`\<`TQueryKey`\> | `undefined` | Include queries matching this query key |
33| <a id="filters-property-stale"></a> `stale?` | `boolean` | `undefined` | Include or exclude stale queries |
34| <a id="filters-property-type"></a> `type?` | `QueryTypeFilter` | `'all'` | Filter to active queries, inactive queries or all queries |
35β
36### options?
37β
38[`InjectIsFetchingOptions`](../interfaces/InjectIsFetchingOptions.md)
39β
40Additional configuration
41β
42<a id="options-properties"></a>
43β
44#### `options` properties
45β
46| Property | Type | Description |
47| ------ | ------ | ------ |
48| <a id="options-property-injector"></a> `injector?` | `Injector` | The `Injector` in which to create the isFetching signal. If this is not provided, the current injection context will be used instead (via `inject`). |
49β
50## Returns
51β
52`Signal`\<`number`\>
53β
54A `Signal` with the number of queries that your application is currently loading or fetching in
55the background.
56β
57## Examples
58β
59```angular-ts
60@Component({
61 selector: 'posts-fetching-indicator',
62 template: `
63 @if (isFetchingPosts()) {
64 <span>Refreshing posts...</span>
65 }
66 `,
67})
68export class PostsFetchingIndicator {
69 // How many queries matching the posts prefix are fetching?
70 readonly isFetchingPosts = injectIsFetching({ queryKey: ['posts'] })
71}
72```
73β
74A global loading indicator for any query fetching in the background, not just the ones on screen:
75```angular-ts
76@Component({
77 selector: 'global-loading-indicator',
78 template: `
79 @if (isFetching()) {
80 <div>Queries are fetching in the background...</div>
81 }
82 `,
83})
84export class GlobalLoadingIndicator {
85 readonly isFetching = injectIsFetching()
86}
87```