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

posts.component.ts

27 lines705 Bytes

1import {
2 ChangeDetectionStrategy,
3 Component,
4 EventEmitter,
5 Output,
6 inject,
7} from '@angular/core'
8import { QueryClient, injectQuery } from '@tanstack/angular-query-experimental'
9import { lastValueFrom } from 'rxjs'
10import { PostsService } from '../services/posts-service'
11​
12@Component({
13 changeDetection: ChangeDetectionStrategy.OnPush,
14 selector: 'posts',
15 templateUrl: './posts.component.html',
16})
17export class PostsComponent {
18 queryClient = inject(QueryClient)
19 #postsService = inject(PostsService)
20​
21 @Output() setPostId = new EventEmitter<number>()
22​
23 postsQuery = injectQuery(() => ({
24 queryKey: ['posts'],
25 queryFn: () => lastValueFrom(this.#postsService.allPosts$()),
26 }))