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

posts.component.ts

28 lines725 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 standalone: true,
16 templateUrl: './posts.component.html',
17})
18export class PostsComponent {
19 queryClient = inject(QueryClient)
20 #postsService = inject(PostsService)
21​
22 @Output() setPostId = new EventEmitter<number>()
23​
24 postsQuery = injectQuery(() => ({
25 queryKey: ['posts'],
26 queryFn: () => lastValueFrom(this.#postsService.allPosts$()),
27 }))