MCPcopy Index your code
hub / github.com/TanStack/query / PostComponent

Class PostComponent

examples/angular/basic/src/app/components/post.component.ts:17–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 templateUrl: './post.component.html',
16})
17export class PostComponent {
18 readonly #postsService = inject(PostsService)
19
20 readonly setPostId = output<number>()
21 readonly postId = input(0)
22
23 readonly postQuery = injectQuery(() => ({
24 enabled: this.postId() > 0,
25 queryKey: ['post', this.postId()],
26 queryFn: (context) => {
27 // Cancels the request when component is destroyed before the request finishes
28 const abort$ = fromEvent(context.signal, 'abort')
29 return lastValueFrom(
30 this.#postsService.postById$(this.postId()).pipe(takeUntil(abort$)),
31 )
32 },
33 }))
34}

Callers

nothing calls this directly

Calls 1

injectQueryFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…