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

injectIsFetching.md

82 lines2.3 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<readonly unknown[]>, "fetchStatus">, options?: InjectIsFetchingOptions): Signal<number>;
10```
11​
12Defined 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)
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)\<readonly `unknown`[]\>, `"fetchStatus"`\>
22​
23The [QueryFilters](../interfaces/QueryFilters.md) to narrow down the matched queries.
24​
25<a id="filters-properties"></a>
26​
27#### `filters` properties
28​
29Built from [`QueryFilters`](../interfaces/QueryFilters.md#properties). See the type above for what it changes.
30​
31### options?
32​
33[`InjectIsFetchingOptions`](../interfaces/InjectIsFetchingOptions.md)
34​
35Additional configuration
36​
37<a id="options-properties"></a>
38​
39#### `options` properties
40​
41| Property | Type | Description |
42| ------ | ------ | ------ |
43| <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`). |
44​
45## Returns
46​
47`Signal`\<`number`\>
48​
49A `Signal` with the number of queries that your application is currently loading or fetching in
50the background.
51​
52## Examples
53​
54```angular-ts
55@Component({
56 selector: 'posts-fetching-indicator',
57 template: `
58 @if (isFetchingPosts()) {
59 <span>Refreshing posts...</span>
60 }
61 `,
62})
63export class PostsFetchingIndicator {
64 // How many queries matching the posts prefix are fetching?
65 readonly isFetchingPosts = injectIsFetching({ queryKey: ['posts'] })
67```
68​
69A global loading indicator for any query fetching in the background, not just the ones on screen:
70```angular-ts
71@Component({
72 selector: 'global-loading-indicator',
73 template: `
74 @if (isFetching()) {
75 <div>Queries are fetching in the background...</div>
76 }
77 `,
78})
79export class GlobalLoadingIndicator {
80 readonly isFetching = injectIsFetching()
82```