@tanstack/angular-query-experimental 5.53.2 → 5.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/README.md +84 -66
- package/package.json +2 -2
package/build/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
# Angular Query
|
|
9
9
|
|
|
10
|
-
> IMPORTANT: This library is currently in an experimental stage. This means that breaking changes
|
|
10
|
+
> IMPORTANT: This library is currently in an experimental stage. This means that breaking changes may happen in minor AND patch releases. Upgrade carefully. If you use this in production while in experimental stage, please lock your version to a patch-level version to avoid unexpected breaking changes.
|
|
11
11
|
|
|
12
12
|
Functions for fetching, caching and updating asynchronous data in Angular
|
|
13
13
|
|
|
@@ -29,87 +29,105 @@ Visit https://tanstack.com/query/latest/docs/framework/angular/overview
|
|
|
29
29
|
|
|
30
30
|
# Quick Start
|
|
31
31
|
|
|
32
|
-
> Angular Query requires Angular 16.
|
|
32
|
+
> Angular Query requires Angular 16 or higher.
|
|
33
33
|
|
|
34
34
|
1. Install `angular-query`
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
```bash
|
|
37
|
+
$ npm i @tanstack/angular-query-experimental
|
|
38
|
+
```
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
or
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
```bash
|
|
43
|
+
$ pnpm add @tanstack/angular-query-experimental
|
|
44
|
+
```
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
or
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
```bash
|
|
49
|
+
$ yarn add @tanstack/angular-query-experimental
|
|
50
|
+
```
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
or
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
```bash
|
|
55
|
+
$ bun add @tanstack/angular-query-experimental
|
|
56
|
+
```
|
|
57
57
|
|
|
58
58
|
2. Initialize **Angular Query** by adding **provideAngularQuery** to your application
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
```ts
|
|
61
|
+
import { provideAngularQuery } from '@tanstack/angular-query-experimental'
|
|
62
|
+
import { QueryClient } from '@tanstack/angular-query-experimental'
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
bootstrapApplication(AppComponent, {
|
|
65
|
+
providers: [provideAngularQuery(new QueryClient())],
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
or in a NgModule-based app
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
```ts
|
|
72
|
+
import { provideHttpClient } from '@angular/common/http'
|
|
73
|
+
import {
|
|
74
|
+
provideAngularQuery,
|
|
75
|
+
QueryClient,
|
|
76
|
+
} from '@tanstack/angular-query-experimental'
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
@NgModule({
|
|
79
|
+
declarations: [AppComponent],
|
|
80
|
+
imports: [BrowserModule],
|
|
81
|
+
providers: [provideAngularQuery(new QueryClient())],
|
|
82
|
+
bootstrap: [AppComponent],
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
85
|
|
|
86
86
|
3. Inject query
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
4. If you need to update options on your query dynamically, make sure to pass them as signals
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
88
|
+
```ts
|
|
89
|
+
import { injectQuery } from '@tanstack/angular-query-experimental'
|
|
90
|
+
import { Component } from '@angular/core'
|
|
91
|
+
|
|
92
|
+
@Component({...})
|
|
93
|
+
export class TodosComponent {
|
|
94
|
+
info = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList }))
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
4. If you need to update options on your query dynamically, make sure to pass them as signals. The query will refetch automatically if data for an updated query key is stale or not present.
|
|
99
|
+
|
|
100
|
+
[Open in StackBlitz](https://stackblitz.com/github/TanStack/query/tree/main/examples/angular/router)
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
@Component({})
|
|
104
|
+
export class PostComponent {
|
|
105
|
+
#postsService = inject(PostsService)
|
|
106
|
+
postId = input.required({
|
|
107
|
+
transform: numberAttribute,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
postQuery = injectQuery(() => ({
|
|
111
|
+
queryKey: ['post', this.postId()],
|
|
112
|
+
queryFn: () => {
|
|
113
|
+
return lastValueFrom(this.#postsService.postById$(this.postId()))
|
|
114
|
+
},
|
|
115
|
+
}))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Injectable({
|
|
119
|
+
providedIn: 'root',
|
|
120
|
+
})
|
|
121
|
+
export class PostsService {
|
|
122
|
+
#http = inject(HttpClient)
|
|
123
|
+
|
|
124
|
+
postById$ = (postId: number) =>
|
|
125
|
+
this.#http.get<Post>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface Post {
|
|
129
|
+
id: number
|
|
130
|
+
title: string
|
|
131
|
+
body: string
|
|
132
|
+
}
|
|
133
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-query-experimental",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.54.1",
|
|
4
4
|
"description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
|
|
5
5
|
"author": "Arnoud de Vries",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"tslib": "^2.6.3",
|
|
52
|
-
"@tanstack/query-core": "5.
|
|
52
|
+
"@tanstack/query-core": "5.54.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@analogjs/vite-plugin-angular": "^1.6.4",
|