Open History to see the last commit
1import {
2 ChangeDetectionStrategy,
3 Component,
4 EventEmitter,
5 Output,
6 inject,
7} from '@angular/core'
8import { QueryClient, injectQuery } from '@tanstack/angular-query'
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 }))
27}