Skip to content

Commit 7ff544e

Browse files
authored
docs(angular-query): improve queryOptions code snippets (#8601)
1 parent ebe996d commit 7ff544e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

docs/framework/angular/guides/query-options.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,28 @@ export class QueriesService {
3131

3232
// usage:
3333

34+
postId = input.required({
35+
transform: numberAttribute,
36+
})
3437
queries = inject(QueriesService)
3538

36-
injectQuery(this.queries.post(1))
37-
injectQueries({
38-
queries: [this.queries.post(1), this.queries.post(2)],
39-
})
39+
postQuery = injectQuery(() => this.queries.post(this.postId()))
40+
4041
queryClient.prefetchQuery(this.queries.post(23))
41-
queryClient.setQueryData(this.queries.post(42).queryKey, newGroups)
42+
queryClient.setQueryData(this.queries.post(42).queryKey, newPost)
4243
```
4344

4445
[//]: # 'Example1'
46+
[//]: # 'Example2'
47+
48+
```ts
49+
// Type inference still works, so query.data will be the return type of select instead of queryFn
50+
queries = inject(QueriesService)
51+
52+
query = injectQuery(() => ({
53+
...groupOptions(1),
54+
select: (data) => data.title,
55+
}))
56+
```
57+
58+
[//]: # 'Example2'

0 commit comments

Comments
 (0)