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

posts.component.ts

32 lines763 Bytes

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