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

injectIsMutating.md

69 lines2.3 KB

1---
2id: injectIsMutating
3title: injectIsMutating
4---
5​
6```ts
7function injectIsMutating(filters?: MutationFilters<unknown, Error, unknown, unknown>, options?: InjectIsMutatingOptions): Signal<number>;
8```
9​
10Defined in: [packages/angular-query-experimental/src/inject-is-mutating.ts:47](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-is-mutating.ts#L47)
11​
12Injects a signal that tracks the number of mutations that your application currently has `pending`
13(useful for app-wide loading indicators).
14​
15## Parameters
16​
17### filters?
18​
19[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>
20​
21The [MutationFilters](../interfaces/MutationFilters.md) to narrow down the matched mutations.
22​
23<a id="filters-properties"></a>
24​
25#### `filters` properties
26​
27| Property | Type | Description |
28| ------ | ------ | ------ |
29| <a id="filters-property-exact"></a> `exact?` | `boolean` | Match mutation key exactly |
30| <a id="filters-property-mutationkey"></a> `mutationKey?` | readonly `unknown`[] | Include mutations matching this mutation key |
31| <a id="filters-property-predicate"></a> `predicate?` | (`mutation`: [`Mutation`](../classes/Mutation.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `boolean` | Include mutations matching this predicate function |
32| <a id="filters-property-status"></a> `status?` | `"error"` \| `"pending"` \| `"success"` \| `"idle"` | Filter by mutation status |
33​
34### options?
35​
36[`InjectIsMutatingOptions`](../interfaces/InjectIsMutatingOptions.md)
37​
38Additional configuration
39​
40<a id="options-properties"></a>
41​
42#### `options` properties
43​
44| Property | Type | Description |
45| ------ | ------ | ------ |
46| <a id="options-property-injector"></a> `injector?` | `Injector` | The `Injector` in which to create the isMutating signal. If this is not provided, the current injection context will be used instead (via `inject`). |
47​
48## Returns
49​
50`Signal`\<`number`\>
51​
52A `Signal` with the number of mutations that your application currently has `pending`.
53​
54## Example
55​
56```angular-ts
57@Component({
58 selector: 'posts-mutating-indicator',
59 template: `
60 @if (isMutatingPosts()) {
61 <span>Saving posts...</span>
62 }
63 `,
64})
65export class PostsMutatingIndicator {
66 // How many mutations matching the posts prefix are in progress?
67 readonly isMutatingPosts = injectIsMutating({ mutationKey: ['posts'] })
69```